Prognosis.DependencyInjection
2.1.0
dotnet add package Prognosis.DependencyInjection --version 2.1.0
NuGet\Install-Package Prognosis.DependencyInjection -Version 2.1.0
<PackageReference Include="Prognosis.DependencyInjection" Version="2.1.0" />
<PackageVersion Include="Prognosis.DependencyInjection" Version="2.1.0" />
<PackageReference Include="Prognosis.DependencyInjection" />
paket add Prognosis.DependencyInjection --version 2.1.0
#r "nuget: Prognosis.DependencyInjection, 2.1.0"
#:package Prognosis.DependencyInjection@2.1.0
#addin nuget:?package=Prognosis.DependencyInjection&version=2.1.0
#tool nuget:?package=Prognosis.DependencyInjection&version=2.1.0
Prognosis.DependencyInjection
Microsoft.Extensions.DependencyInjection integration for the Prognosis service health graph. Provides assembly scanning, a fluent graph builder, and hosted service monitoring.
Installation
dotnet add package Prognosis.DependencyInjection
Quick start
using Prognosis.DependencyInjection;
builder.Services.AddPrognosis(health =>
{
health.ScanForServices(typeof(Program).Assembly);
health.AddComposite("Application", app =>
{
app.DependsOn<AuthService>(ServiceImportance.Required);
app.DependsOn("NotificationSystem", ServiceImportance.Important);
});
health.AddRoots("Application");
health.UseMonitor(TimeSpan.FromSeconds(30));
});
API
Assembly scanning
ScanForServices discovers all concrete IServiceHealth implementations in the given assemblies and registers them as singletons. It also reads [DependsOn<T>] attributes to auto-wire dependency edges:
[DependsOn<DatabaseService>(ServiceImportance.Required)]
[DependsOn<CacheService>(ServiceImportance.Important)]
class AuthService : IObservableServiceHealth
{
private readonly ServiceHealthTracker _health = new();
public string Name => "AuthService";
public IReadOnlyList<ServiceDependency> Dependencies => _health.Dependencies;
public IObservable<HealthStatus> StatusChanged => _health.StatusChanged;
public void NotifyChanged() => _health.NotifyChanged();
public HealthEvaluation Evaluate() => _health.Evaluate();
}
Composite nodes
Define virtual aggregation points whose health is derived entirely from their dependencies:
health.AddComposite("NotificationSystem", n =>
{
n.DependsOn("MessageQueue", ServiceImportance.Required);
n.DependsOn("EmailProvider", ServiceImportance.Optional);
});
Dependencies can reference services by type (DependsOn<T>) or by name (DependsOn("name")).
Delegate wrappers
Wrap a DI-registered service you don't own with a health-check delegate:
health.AddDelegate<ThirdPartyEmailClient>("EmailProvider",
client => client.IsConnected
? HealthStatus.Healthy
: new HealthEvaluation(HealthStatus.Unhealthy, "SMTP refused"));
Roots
Mark named services as top-level graph entry points for monitoring and report generation:
health.AddRoots("Application");
HealthGraph
The materialized graph is registered as a singleton. Inject it to access the roots, look up services by name, or create reports:
var graph = serviceProvider.GetRequiredService<HealthGraph>();
// Create a point-in-time report.
HealthReport report = graph.CreateReport();
// Look up a service by name.
IServiceHealth db = graph["Database"];
// Enumerate all services.
foreach (var svc in graph.Services)
{
Console.WriteLine($"{svc.Name}: {svc.Evaluate()}");
}
The Roots property is IServiceHealth[], directly compatible with the Rx extensions in Prognosis.Reactive:
graph.Roots.PollHealthReport(TimeSpan.FromSeconds(30)).Subscribe(...);
Hosted monitoring
UseMonitor registers HealthMonitor as an IHostedService that polls on the given interval and stops with the host:
health.UseMonitor(TimeSpan.FromSeconds(30));
This is optional — Rx users can skip it and build their own pipeline from HealthGraph.Roots.
Dependencies
- Prognosis (core library)
- Microsoft.Extensions.DependencyInjection.Abstractions >= 9.0.0
- Microsoft.Extensions.Hosting.Abstractions >= 9.0.0
Requirements
- .NET Standard 2.0+ (.NET Framework 4.6.1+, .NET Core 2.0+, .NET 5+)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.5)
- Prognosis (>= 2.1.0)
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.5)
- Prognosis (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.