The ISystemClock defines a way to get the current time in UTC timezone, and it has a simple implementation:
public interface ISystemClock
{
DateTimeOffset UtcNow { get; }
}
public interface SystemClock : ISystemClock
{
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
}
The interface exists in:
Microsoft.AspNetCore.Authentication
Microsoft.AspNetCore.ResponseCaching
Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
Microsoft.Extensions.Internal
There is a small difference exists between implementations, but in most cases it can be moved out. In case of Kestrel's clock which has a specific logic inside, there could be made a new interface IScopedSystemClock which will provide the scope start time as UtcNow does now. Therefore, looks like all of them could be merged into a single class/interface and put into Microsoft.Extensions.Primitives.
The
ISystemClockdefines a way to get the current time in UTC timezone, and it has a simple implementation:The interface exists in:
Microsoft.AspNetCore.AuthenticationMicrosoft.AspNetCore.ResponseCachingMicrosoft.AspNetCore.Server.Kestrel.Core.Internal.InfrastructureMicrosoft.Extensions.InternalThere is a small difference exists between implementations, but in most cases it can be moved out. In case of Kestrel's clock which has a specific logic inside, there could be made a new interface
IScopedSystemClockwhich will provide the scope start time asUtcNowdoes now. Therefore, looks like all of them could be merged into a single class/interface and put intoMicrosoft.Extensions.Primitives.