NodaTimeProviderExtensions
Namespace: SnowBank.Threading · class
Extensions for consuming NodaTime instants from a plain TimeProvider
Methods
AddSystemClock
static IServiceCollection AddSystemClock(IServiceCollection services, TimeProvider source = null)
Registers the system clock as a NodaTimeProvider singleton, aliased as both TimeProvider and IClock
services— Service collection to register intosource— Underlying source of time;nulluses the real system clock (a test passes its fake advanceable provider)
Uses TryAdd semantics: a test harness that registered its own (fake-backed) clock FIRST wins, and this call becomes a no-op - so libraries and startup code can call it unconditionally.
GetCurrentInstant
static Instant GetCurrentInstant(TimeProvider provider)
Reads the current instant from this provider (the NodaTime equivalent of GetUtcNow)
Lets scheduling code inject ONLY a and still produce s, instead of injecting both a provider and an .