MartenInstaller
Key: Marten
Default Enabled: ✅ (when added via AddCritterStack())
Package: SaveApis.Utils.CritterStack
Purpose
Configures Marten as a PostgreSQL-backed document database and event store with multi-tenancy (Conjoined), event sourcing, Wolverine integration, and an async projection daemon.
What It Does
Builder phase:
- Builds a
NpgsqlConnectionStringfrom theMartenconfiguration section- In
Development: enablesIncludeErrorDetailandLogParameters
- In
- Calls
builder.Services.AddMarten(options => { ... })with:- PostgreSQL connection string from configuration
- System.Text.Json serialization with enums as strings
- Npgsql logging disabled
- Identity map for aggregates in both event store and projections
- Tenancy:
TenancyStyle.Conjoinedfor all documents and events - Archived stream partitioning enabled
- Document metadata:
CreatedAtandCorrelationIdenabled - OpenTelemetry connection tracking at
Normallevel + event counters
.UseLightweightSessions()— all sessions are lightweight by default.IntegrateWithWolverine()— enables Wolverine/Marten integration for outbox, saga persistence, and event processing.AddAsyncDaemon(mode)— starts the projection daemon in the configured mode
Dependencies
No explicit installer dependencies. Must be registered after CritterStackInstaller (guaranteed by AddCritterStack() registration order).
Configuration
appsettings.json
{
"Marten": {
"Host": "localhost",
"Port": 5432,
"Database": "my_service",
"Username": "postgres",
"Password": "secret",
"Mode": "HotCold"
}
}
Environment Variables
| Variable | Type | Default | Required | Description |
|---|---|---|---|---|
Marten__Host |
string |
– | Yes | PostgreSQL host |
Marten__Port |
int |
– | Yes | PostgreSQL port |
Marten__Database |
string |
– | Yes | Database name |
Marten__Username |
string |
– | Yes | Database username |
Marten__Password |
string |
– | Yes | Database password |
Marten__Mode |
DaemonMode |
HotCold |
No | Async daemon mode |
Example:
Marten__Host=db.example.com
Marten__Port=5432
Marten__Database=my_service_db
Marten__Username=app_user
Marten__Password=s3cr3t
Marten__Mode=HotCold
DaemonMode Values
| Value | Description |
|---|---|
HotCold |
Leader election — one node runs projections at a time (recommended for multi-instance deployments) |
Solo |
Always runs projections, regardless of other instances |
Disabled |
No projection daemon started |
Multi-Tenancy
All documents and events use TenancyStyle.Conjoined, meaning tenant data is stored in the same tables with a tenant identifier column. Queries are automatically scoped to the active tenant via Marten’s session API.
Notes
ResourceAutoCreate = All(set byCritterStackInstaller) means Marten will create or migrate all required tables on startup — no manual migrations needed in development.- In production, consider whether auto-migration on startup is appropriate for your deployment strategy.
- The application name from
SaveApisApplication.Nameis set on the Npgsql connection for easier identification in PostgreSQL activity views.
Related
- CritterStack Overview
- CritterStackInstaller — sets JasperFx defaults required by Marten
- WolverineInstaller — integrated with Marten for outbox and event handling