You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirm you've already contributed to this project or that you sponsor it
I confirm I'm a sponsor or a contributor
Describe the solution you'd like
Hello, I want to replace DateTimeOffset.UtcNow with TimeProvider.GetUtcNow(). TimeProvider will be passed from the service container.
Why?
I am running integration tests in which I use TimeProvider to control what Now means. Unfortunately, Openiddict does not use it, and it fails this attempt.
Thanks for your offer! It's something I considered too, so 👍🏻
A few notes, in no particular order:
TimeProvider can technically be used on .NET Standard 2.0/.NET Framework 4.6.2+ thanks to the package you mentioned, but since the Microsoft.Extensions/Microsoft.Bcl packages are tied to the .NET release matching their package version (i.e they have the same support policy), we'll want to use TimeProvider only on .NET 8.0+ and keep using DateTime.UtcNow/DateTimeOffset.UtcNow for the other TFMs. For that, we'll need to add a SUPPORTS_TIME_PROVIDER compilation constant in Directory.Build.targets. You can take a look at what's been done for SUPPORTS_HTTP_CLIENT_RESILIENCE for some inspiration 😃
Retrieving TimeProvider directly from DI would work, but I'd prefer if we attached it to OpenIddict*Options and had an OpenIddict*Configuration class implementing IPostConfigureOptions<OpenIddict*Options> to resolve a default, DI-provided instance when no provider has been explicitly added (it's the pattern used in ASP.NET Core for the authentication handlers: https://github.com/dotnet/aspnetcore/blob/e8eeea60605f323014ab86ea34c2bd87ca8e84d7/src/Security/Authentication/Core/src/AuthenticationBuilder.cs#L141). DateTimeOffset.UtcNow is used in multiple projects, so we'll need to update a few options classes 😄
DateTime.UtcNow is used in the EF 6, EF Core and MongoDB stores, but since it's used for a LINQ query that is translated to SQL, we'll want to keep using it to ensure it's correctly mapped to GETUTCDATE().
Confirm you've already contributed to this project or that you sponsor it
Describe the solution you'd like
Hello, I want to replace
DateTimeOffset.UtcNow
withTimeProvider.GetUtcNow()
.TimeProvider
will be passed from the service container.Why?
I am running integration tests in which I use
TimeProvider
to control whatNow
means. Unfortunately, Openiddict does not use it, and it fails this attempt.Does it sound like something you would like?
See https://www.nuget.org/packages/Microsoft.Bcl.TimeProvider/8.0.1#readme-body-tab
Additional context
No response
The text was updated successfully, but these errors were encountered: