Host SquidStd in an ASP.NET Core app
Wire SquidStd into an ASP.NET Core Minimal API and expose its health checks over HTTP.
What you'll build
A Minimal API web app that uses SquidStd (SquidStd.AspNetCore) as its DryIoc-backed service provider, surfaces
the registered SquidStd health checks at /health, and answers a simple root endpoint.
Prerequisites
- .NET 10 SDK
dotnet add package SquidStd.AspNetCore
Steps
1. Register SquidStd on the builder
UseSquidStd swaps in DryIoc as the ASP.NET Core service provider and bootstraps SquidStd. The root directory is
taken from the host environment automatically, so you only set the config name. The bootstrap registers only the
configuration core; pass a container callback as the second argument and call RegisterCoreServices() there to
bring up the core services.
builder.UseSquidStd(
o => o.ConfigName = "squidstd",
container => container.RegisterCoreServices()
);
2. Bridge the health checks
AddSquidStdHealthChecks registers every SquidStd IHealthCheck as a standard ASP.NET Core health check. Call it
after UseSquidStd.
builder.AddSquidStdHealthChecks();
3. Build the app and map endpoints
Build the app, expose the health checks with the standard MapHealthChecks, add a root endpoint, and run.
var app = builder.Build();
app.MapHealthChecks("/health");
app.MapGet("/", () => "SquidStd up");
app.Run();
Unified Serilog logging
Add AddSquidStdSerilog() to send ASP.NET Core framework logs (Kestrel, Microsoft.Hosting.Lifetime)
through the same Serilog logger SquidStd configures from squidstd.yaml, giving a single format and a
single configuration source:
builder.UseSquidStd(options => options.ConfigName = "squidstd", c => c.RegisterCoreServices());
builder.AddSquidStdSerilog();
builder.AddSquidStdHealthChecks();
Without this call the two loggers stay separate (two console formats). With it, squidstd.yaml drives
all logging.
Run it
dotnet run --project samples/SquidStd.Samples.AspNetCore
Browse to / for the "SquidStd up" message and to /health for the aggregated health-check status.
How it works
UseSquidStd creates an owned DryIoc container, registers it through DryIocServiceProviderFactory, and hooks the
SquidStd lifecycle into the ASP.NET Core host via a hosted service. AddSquidStdHealthChecks resolves the SquidStd
IHealthCheck instances from that container and adapts each one into the standard health-check pipeline, so
MapHealthChecks reports them like any other ASP.NET Core check.
See also
- SquidStd.AspNetCore reference
- Previous: Getting started