Skip to content

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:

csharp
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

csharp
// 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:

csharp
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:

csharp
app.MapHub<CommunicationHub>("/api/messages");

Static Files (Embedded SPA):

  • Configures StaticFileMiddleware to serve embedded Vue SPA resources
  • Falls back to index.html for 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:

csharp
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.

Released under the MIT License.