diff --git a/CLAUDE.md b/CLAUDE.md index e2c15d4..b9a02ad 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -22,11 +22,11 @@ Build artifacts go to `/artifacts/bin/` (configured in `Directory.Build.props`). |---|---| | `Abstractions/` | `IHealthMonitor`, `IStopwatch`, `ISystemTimeProvider` | | `Detection/` | `RealStopwatch`, `SystemTimeProvider` — production implementations of the abstractions | -| `Monitors/` | `HealthMonitorBase` (state machine), `NamedHealthMonitor`, `HealthMonitorCoordinator`, `DynamicHealthMonitorManager` | +| `Monitors/` | `HealthMonitorBase` (state machine), `NamedHealthMonitor`, `HealthMonitorCoordinator` (fans out `Tick()` to all registered monitors), `DynamicHealthMonitorManager` | | `Services/` | `HealthMonitorHostedService` — background loop, ticks coordinator at `MinCheckInterval` | -| `Configuration/` | `HealthMonitorOptions`, `HealthMonitorRegistration` | +| `Configuration/` | `HealthMonitorOptions` (thresholds/intervals), `HealthMonitorRegistration` (name + options pair used at DI registration) | | `Extensions/` | `AddHealthMonitor()` DI extension | -| `Events/` | `HealthDegradedEventArgs`, `HealthRecoveredEventArgs` | +| `Events/` | `HealthEventArgs` (base), `HealthDegradedEventArgs`, `HealthRecoveredEventArgs` | ### State machine diff --git a/Directory.Packages.props b/Directory.Packages.props index b7a20d1..d4961c4 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -2,39 +2,14 @@ true - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - + diff --git a/README.md b/README.md index 0789bf5..7d6d1e3 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,20 @@ foreach (var monitor in provider.GetRequiredService> } ``` +**`netstandard2.0` — resolve by name without keyed services:** + +Keyed DI is not available on `netstandard2.0`. Filter the `IEnumerable` by name instead: + +```csharp +var monitors = provider.GetRequiredService>(); +var monitor = monitors.First(m => m.Name == "quote-feed"); + +monitor.Degraded += (_, e) => Console.WriteLine($"{e.MonitorName}: degraded"); +monitor.Recovered += (_, e) => Console.WriteLine($"{e.MonitorName}: recovered"); +``` + +Alternatively, use `DynamicHealthMonitorManager` which requires no DI at all and is fully supported on `netstandard2.0`. + ### Sending Heartbeats ```csharp @@ -229,6 +243,20 @@ foreach (var monitor in provider.GetRequiredService> } ``` +**`netstandard2.0` — 不使用键控服务按名称解析:** + +`netstandard2.0` 下不支持键控 DI,可通过 `IEnumerable` 按名称筛选: + +```csharp +var monitors = provider.GetRequiredService>(); +var monitor = monitors.First(m => m.Name == "quote-feed"); + +monitor.Degraded += (_, e) => Console.WriteLine($"{e.MonitorName}: 降级"); +monitor.Recovered += (_, e) => Console.WriteLine($"{e.MonitorName}: 恢复"); +``` + +也可以使用 `DynamicHealthMonitorManager`,它完全不依赖 DI,在 `netstandard2.0` 上同样可用。 + ### 发送心跳 ```csharp