Hosting Extensions
The CritterWatch.Services package exposes two extension methods for ASP.NET Core applications.
AddCritterWatch()
Registers all CritterWatch dependencies into the ASP.NET Core IServiceCollection / IHostApplicationBuilder:
builder.AddCritterWatch(
connectionString: "Host=localhost;Database=critterwatch;...",
configureWolverine: opts =>
{
opts.UseRabbitMq(new Uri("amqp://localhost")).AutoProvision();
opts.ListenToRabbitQueue("critterwatch").Sequential();
});What it registers
- Wolverine — handlers for incoming telemetry and outgoing operator commands; routing for the configured transport.
- Marten — the console's own PostgreSQL schema (
critterwatch) for state, history, alerts, and audit log. - SignalR hub — push channel to the browser, configured with camelCase + string-enum JSON.
- Alert evaluator — runs on a 30-second pass evaluating thresholds against incoming telemetry.
- Background maintenance — retention enforcement, periodic cleanup.
- Health checks — basic Postgres connectivity check.
Overloads
// Connection string + Wolverine config
builder.AddCritterWatch(connectionString, configureWolverine);
// Connection string + Wolverine config + alert thresholds
builder.AddCritterWatch(connectionString, configureWolverine, configureAlerts);
// Full options object
builder.AddCritterWatch(options => {
options.ConnectionString = "...";
options.SignalRRoute = "/api/messages";
options.ConfigureWolverine = opts => { ... };
options.ConfigureAlerts = alerts => { ... };
});UseCritterWatch()
Maps CritterWatch middleware into the ASP.NET Core request pipeline:
app.UseCritterWatch();
// With custom SignalR route:
app.UseCritterWatch(signalRRoute: "/my-hub");What It Maps
Wolverine HTTP:
- Maps all HTTP endpoints defined with
[WolverineGet],[WolverinePost], etc. in CritterWatch.Services - These are mounted under
/api/critterwatch/*
SignalR Hub:
app.MapHub<CommunicationHub>("/api/messages");Static Files (Embedded SPA):
- Configures
StaticFileMiddlewareto serve embedded Vue SPA resources - Falls back to
index.htmlfor all unmatched routes (client-side routing)
Call Order
UseCritterWatch() should be called after UseRouting() and any authentication/authorization middleware, but before the fallback handler. The typical order is:
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseCritterWatch();
app.Run();Schema isolation
The console's bookkeeping lives in its own dedicated critterwatch schema. It doesn't collide with — and doesn't read from — any other Marten stores you may configure in the same database.
You can point the console at a database that's already used by another application; it'll create its schema, leave everything else alone, and run side-by-side.
Connection-string security
The PostgreSQL connection string is read from your console's configuration and stays there. It is not transmitted to monitored services or the browser. Use appsettings.json with environment-variable overrides (or your secret manager of choice) for production deployments.
