dotnet / dotnet/dotnet-api-docs
Update TimeProvider documentation to mention how it should be added to the DI
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
There appears to be very little documentation on the new `TimeProvider` functionality. I had to go google around to see how this thing was expected to be registered in the DI.
Eventually I did find that I had to do this:
`services.TryAddSingleton(TimeProvider.System);`
Sadly, this doesn't seem to be documented anywhere. It might be good to at least mention it as a remark on the [System.TimeProvider](https://learn.microsoft.com/en-us/dotnet/api/system.timeprovider?view=net-8.0) page.
Additionally, I think it would make sense to provide an extension method on `IServiceCollection` along the lines of `AddTimeProvider()`, like for example `AddHttpContextAccessor()` and `AddMemoryCache()`.
Contributor guide
Assessment
This issue has not been assessed yet.