ImanSoftware.DateTimeProvider
1.0.0
dotnet add package ImanSoftware.DateTimeProvider --version 1.0.0
NuGet\Install-Package ImanSoftware.DateTimeProvider -Version 1.0.0
<PackageReference Include="ImanSoftware.DateTimeProvider" Version="1.0.0" />
<PackageVersion Include="ImanSoftware.DateTimeProvider" Version="1.0.0" />
<PackageReference Include="ImanSoftware.DateTimeProvider" />
paket add ImanSoftware.DateTimeProvider --version 1.0.0
#r "nuget: ImanSoftware.DateTimeProvider, 1.0.0"
#:package ImanSoftware.DateTimeProvider@1.0.0
#addin nuget:?package=ImanSoftware.DateTimeProvider&version=1.0.0
#tool nuget:?package=ImanSoftware.DateTimeProvider&version=1.0.0
ImanSoftware.DateTimeProvider
Version: 1.0.0 | Last Updated: August 2026
A lightweight abstraction over
System.DateTimefor clean, testable, and dependency-injected date and time access.
ImanSoftware.DateTimeProvider eliminates direct dependencies on DateTime.Now and DateTime.Today by providing a simple, injectable abstraction. This makes your applications easier to test, maintain, and extend.
Installation
Install the package using the .NET CLI:
dotnet add package ImanSoftware.DateTimeProvider
Why DateTimeProvider?
Using DateTime.Now directly introduces hidden dependencies that make unit testing difficult.
Instead of:
var createdAt = DateTime.Now;
Use:
var createdAt = _dateTimeProvider.Now;
Your code becomes deterministic and can easily be tested by mocking the current time.
Benefits include:
- Improved testability
- Dependency Injection friendly
- Clean Architecture compatible
- Centralized time access
- Lightweight and dependency-free
Features
- ✅
IDateTimeProviderabstraction - ✅
Nowproperty - ✅
Todayproperty - ✅
CurrentTimeOfDayproperty - ✅ Default implementation using
System.DateTime - ✅ Easy Dependency Injection registration
- ✅ Mock-friendly design
- ✅ Zero configuration
IDateTimeProvider
The core abstraction exposes commonly used date and time values.
Available members:
NowTodayCurrentTimeOfDay
Example:
public interface IDateTimeProvider
{
DateTime Now { get; }
DateTime Today { get; }
TimeSpan CurrentTimeOfDay { get; }
}
DefaultDateTimeProvider
The package includes a default implementation that wraps System.DateTime.
var provider = new DefaultDateTimeProvider();
var now = provider.Now;
var today = provider.Today;
var time = provider.CurrentTimeOfDay;
Dependency Injection
Register the provider in your application:
services.AddDateTimeProvider();
After registration, IDateTimeProvider can be injected anywhere in your application.
Example
using ImanSoftware.DateTimeProvider;
public class OrderService
{
private readonly IDateTimeProvider _dateTime;
public OrderService(IDateTimeProvider dateTime)
{
_dateTime = dateTime;
}
public void CreateOrder()
{
var now = _dateTime.Now;
// Business logic...
}
}
Unit Testing
Because the provider is interface-based, replacing it with a mock or fake implementation is straightforward.
var mock = new Mock<IDateTimeProvider>();
mock.Setup(x => x.Now)
.Returns(new DateTime(2026, 1, 1));
Your business logic can now be tested without relying on the system clock.
Design Goals
- Clean abstraction
- High testability
- Dependency Injection friendly
- Lightweight
- Framework independent
- Minimal API
- Zero configuration
- Easy integration
- Clean Architecture compatible
Requirements
- .NET Standard 2.0+
- .NET 6+
- .NET 7+
- .NET 8+
- .NET 9+
- .NET 10.0+
Author
Iman Estiri
📧 contact.imanestiri@gmail.com
📧 dev.imanestiri@gmail.com
GitHub:
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ImanSoftware.DateTimeProvider:
| Package | Downloads |
|---|---|
|
ImanSoftware.Framework
Umbrella package that bundles all ImanSoftware modules for a unified development experience. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 156 | 8/3/2026 |