Skip to content

Hosting Extensions ​

Each console package — CritterWatch (Marten / PostgreSQL), CritterWatch.SqlServer (Polecat / SQL Server) and CritterWatch.Sqlite (Fisher / SQLite) — exposes the same two extension methods for ASP.NET Core applications. They differ only in the first argument: a PostgreSQL connection string or NpgsqlDataSource, a SQL Server connection string, or a SQLite connection string. CritterWatch.Services is the store-agnostic core all three depend on; you do not reference it directly.

AddCritterWatch() ​

An extension on WebApplicationBuilder that registers all CritterWatch dependencies:

cs
builder.AddCritterWatch(
    postgresConnectionString: "Host=localhost;Database=critterwatch;Username=postgres;Password=postgres",
    configureWolverine: opts =>
    {
        opts.UseRabbitMq(new Uri("amqp://localhost")).AutoProvision();
        opts.ListenToRabbitQueue("critterwatch").ProcessInParallelWithNativeAcks().UseCritterWatchSerializer();
    });

What it registers ​

  • Wolverine — handlers for incoming telemetry and outgoing operator commands; routing for the configured transport.
  • The console's store — Marten, Polecat or Fisher, depending on the package, holding state, history, alerts and the audit log in the critterwatch schema (schemaName changes it). Wolverine's own durability tables go in its _wolverine sibling, critterwatch_wolverine by default.
  • Wolverine.HTTP — AddWolverineHttp(), for the HTTP API.
  • SignalR hub — the browser's command and push channel, configured with camelCase + string-enum JSON. When the configuration has a connection string named redis, the hub gets a Redis backplane for a clustered console.
  • Alert evaluator — runs on a 30-second pass evaluating thresholds against incoming telemetry.
  • Background maintenance — retention enforcement, periodic cleanup.
  • Health checks — critterwatch-liveness, critterwatch-system and the console's other checks, mapped by UseCritterWatch() (see below).

Overloads ​

The first argument is either a connection string or (on the Marten package) a pre-built NpgsqlDataSource; the rest are optional: the callbacks (configureWolverine, configureHub), the cluster-partitioning knobs (enableClusterPartitioning, default false, and configureClusterShardedTopology — see Clustering), and schemaName (default critterwatch). On the CritterWatch.Sqlite package enableClusterPartitioning exists only for signature parity and must stay false: a SQLite database is one file with one writer at a time, so several console nodes cannot safely share it.

cs
// Connection string + Wolverine configuration.
builder.AddCritterWatch(connectionString, configureWolverine);

// Also tune the SignalR HubOptions (third argument).
builder.AddCritterWatch(connectionString, configureWolverine, configureHub);

// Or hand in a pre-built NpgsqlDataSource instead of a connection string —
// e.g. the one Aspire injects into DI.
builder.AddCritterWatch(dataSource, configureWolverine);

UseCritterWatch() ​

Maps CritterWatch middleware into the ASP.NET Core request pipeline:

cs
app.UseCritterWatch();

// With a 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:

  • Maps the CritterWatch SignalR communication hub at the configured route (default /api/messages) — the browser's live push channel and the route its operator commands take.

Health endpoints:

  • /health/live (the liveness check only) and /health/ready (every CritterWatch check), mapped before the SPA fallback. Point an orchestrator's liveness probe at /health/live: the SPA shell answers 200 on / even while the console is failing every message. See Probing the CritterWatch console itself.

License check:

  • Outside the Development environment, reads JasperFx:LicenseKey (or the JASPERFX__LICENSEKEY environment variable). Without a valid key the console runs in the Free tier: monitoring works, operator actions are refused. See Licensing.

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:

cs
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseCritterWatch();
app.Run();

Schema isolation ​

The console's bookkeeping lives in its own dedicated critterwatch schema, and Wolverine's durability tables in critterwatch_wolverine. It doesn't collide with — and doesn't read from — any other store you may configure in the same database. On SQLite the schema name becomes a table-name prefix.

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

Running the console inside your own application ​

AddCritterWatch / UseCritterWatch stand up a dedicated console host. To mount the console inside an application you already run, monitoring that application, use opts.AddCritterWatchEmbedded(...) inside your own UseWolverine and app.UseCritterWatchEmbedded() instead. The UI is served under /critterwatch. See Embedded CritterWatch.

AI access (MCP) ​

A console host can also expose the cross-application MCP server so AI agents can read health/performance/alerts and drive action tools. It mounts consumer-wired alongside the hosting calls above (AddCritterWatchMcp() / MapCritterWatchMcp()). See Cross-application MCP server for the mount, the auth posture, and the paid-tier license requirement.