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:
- Configures Wolverine with all CritterWatch message handlers
- Sets up message routing for commands dispatched to monitored services
- Applies the provided
configureWolverineaction for transport setup
Marten:
- Registers Marten with PostgreSQL using the provided connection string
- Schema:
critterwatch - Projections:
ServiceSummaryProjection(single stream),TimelineProjection(cross-stream) - Async projections run in-process via Marten's
AddAsyncDaemon()
SignalR:
- Registers the
CommunicationHub - Configures JSON serialization with camelCase and string enum converters
Alert System:
- Registers alert evaluator services
- Applies default threshold configuration
Other:
- Registers background services for periodic maintenance tasks
- Configures health check services for the Marten database
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();Marten Configuration
CritterWatch creates a dedicated Marten DocumentStore for its internal state. This is independent of any Marten stores your application may configure — they do not conflict.
The store is configured with:
- Schema:
critterwatch(all tables, functions, and sequences live in this schema) - Document types:
ServiceSummary,AgentHealthState,AlertRecord,TimelineEntry - Event types: all 25+ domain event types from
Events.cs - Projections:
ServiceSummaryProjection,TimelineProjection - Async daemon: started automatically for continuous projection updates
Connection String Security
The PostgreSQL connection string is stored only in your application configuration and is never transmitted to monitored services or the browser. Use appsettings.json with environment variable overrides for production deployments.
