diff --git a/examples/SharpFunctional.MSSQL.Example/Program.cs b/examples/SharpFunctional.MSSQL.Example/Program.cs
index 989f896..ea656cd 100644
--- a/examples/SharpFunctional.MSSQL.Example/Program.cs
+++ b/examples/SharpFunctional.MSSQL.Example/Program.cs
@@ -50,7 +50,7 @@
await using var sqlConnection = new SqlConnection(connectionString);
await sqlConnection.OpenAsync();
-var db = new FunctionalMsSqlDb(dbContext: dbContext, connection: sqlConnection);
+var db = new FunctionalMsSqlDb(dbContext: dbContext, dbConnection: sqlConnection);
// ═══════════════════════════════════════════════════════════════════════════
// 2. Seed data — customers, products, orders, and order lines
diff --git a/src/SharpFunctional.MSSQL/Common/CircuitBreaker.cs b/src/SharpFunctional.MSSQL/Common/CircuitBreaker.cs
index 2e0af3a..860c881 100644
--- a/src/SharpFunctional.MSSQL/Common/CircuitBreaker.cs
+++ b/src/SharpFunctional.MSSQL/Common/CircuitBreaker.cs
@@ -74,14 +74,15 @@ public sealed class CircuitBreakerOptions
/// }, cancellationToken);
///
///
-public sealed class CircuitBreaker(CircuitBreakerOptions? options = null)
+public sealed class CircuitBreaker(CircuitBreakerOptions? options = null, TimeProvider? timeProvider = null)
{
private readonly CircuitBreakerOptions _options = options ?? new CircuitBreakerOptions();
+ private readonly TimeProvider _timeProvider = timeProvider ?? TimeProvider.System;
private readonly Lock _stateLock = new();
private CircuitState _state = CircuitState.Closed;
private DateTime _openedAtUtc = DateTime.MinValue;
- private DateTime _stateChangedAtUtc = DateTime.UtcNow;
+ private DateTime _stateChangedAtUtc = (timeProvider ?? TimeProvider.System).GetUtcNow().UtcDateTime;
private int _failureCount;
private int _halfOpenSuccessCount;
@@ -120,7 +121,7 @@ public CircuitBreakerSnapshot GetSnapshot()
{
lock (_stateLock)
{
- var nowUtc = DateTime.UtcNow;
+ var nowUtc = _timeProvider.GetUtcNow().UtcDateTime;
var state = EvaluateState(nowUtc);
return new CircuitBreakerSnapshot(
State: state,
@@ -186,12 +187,12 @@ public void Reset()
_state = CircuitState.Closed;
_failureCount = 0;
_halfOpenSuccessCount = 0;
- _stateChangedAtUtc = DateTime.UtcNow;
+ _stateChangedAtUtc = _timeProvider.GetUtcNow().UtcDateTime;
}
}
/// Must be called inside lock (_stateLock).
- private CircuitState EvaluateState() => EvaluateState(DateTime.UtcNow);
+ private CircuitState EvaluateState() => EvaluateState(_timeProvider.GetUtcNow().UtcDateTime);
/// Must be called inside lock (_stateLock).
private CircuitState EvaluateState(DateTime utcNow)
@@ -215,13 +216,13 @@ private void RecordFailure()
if (_state == CircuitState.HalfOpen)
{
_state = CircuitState.Open;
- _openedAtUtc = DateTime.UtcNow;
+ _openedAtUtc = _timeProvider.GetUtcNow().UtcDateTime;
_stateChangedAtUtc = _openedAtUtc;
}
else if (_state == CircuitState.Closed && _failureCount >= _options.FailureThreshold)
{
_state = CircuitState.Open;
- _openedAtUtc = DateTime.UtcNow;
+ _openedAtUtc = _timeProvider.GetUtcNow().UtcDateTime;
_stateChangedAtUtc = _openedAtUtc;
}
}
@@ -238,7 +239,7 @@ private void RecordSuccess()
_state = CircuitState.Closed;
_failureCount = 0;
_halfOpenSuccessCount = 0;
- _stateChangedAtUtc = DateTime.UtcNow;
+ _stateChangedAtUtc = _timeProvider.GetUtcNow().UtcDateTime;
}
}
else
diff --git a/src/SharpFunctional.MSSQL/Common/FunctionalExtensions.cs b/src/SharpFunctional.MSSQL/Common/FunctionalExtensions.cs
index e029ae5..0969ef3 100644
--- a/src/SharpFunctional.MSSQL/Common/FunctionalExtensions.cs
+++ b/src/SharpFunctional.MSSQL/Common/FunctionalExtensions.cs
@@ -34,8 +34,13 @@ public static async Task