Files
git.stella-ops.org/src/__Libraries/StellaOps.Determinism.Abstractions/DeterminismServiceCollectionExtensions.cs
StellaOps Bot cb898a4ac8 DET-001/002/003: Add IGuidProvider abstraction and refactor Policy.Unknowns for determinism
- Created IGuidProvider interface and SystemGuidProvider in StellaOps.Determinism.Abstractions
- Added SequentialGuidProvider for testing deterministic GUID generation
- Added DeterminismServiceCollectionExtensions with AddDeterminismDefaults()
- Refactored Policy.Unknowns:
  - UnknownsRepository now uses TimeProvider and IGuidProvider
  - BudgetExceededEventFactory accepts optional TimeProvider parameter
  - ServiceCollectionExtensions calls AddDeterminismDefaults()
- Fixed Policy.Exceptions csproj (added ImplicitUsings, Nullable, PackageReferences)

Sprint: SPRINT_20260104_001_BE_determinism_timeprovider_injection
Tasks: DET-001 (audit), DET-002 (IGuidProvider), DET-003 (registration pattern), DET-004 (partial - Policy.Unknowns)
2026-01-04 12:37:12 +02:00

40 lines
1.3 KiB
C#

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace StellaOps.Determinism;
/// <summary>
/// Extension methods for registering determinism abstractions in DI.
/// </summary>
public static class DeterminismServiceCollectionExtensions
{
/// <summary>
/// Adds <see cref="TimeProvider.System"/> as a singleton.
/// </summary>
public static IServiceCollection AddSystemTimeProvider(this IServiceCollection services)
{
services.TryAddSingleton(TimeProvider.System);
return services;
}
/// <summary>
/// Adds <see cref="SystemGuidProvider"/> as the <see cref="IGuidProvider"/> singleton.
/// </summary>
public static IServiceCollection AddSystemGuidProvider(this IServiceCollection services)
{
services.TryAddSingleton<IGuidProvider, SystemGuidProvider>();
return services;
}
/// <summary>
/// Adds both <see cref="TimeProvider.System"/> and <see cref="SystemGuidProvider"/> as singletons.
/// This is the recommended setup for production services.
/// </summary>
public static IServiceCollection AddDeterminismDefaults(this IServiceCollection services)
{
services.AddSystemTimeProvider();
services.AddSystemGuidProvider();
return services;
}
}