Genocs.Saga.Integrations.MongoDB

Genocs.Saga.Integrations.MongoDB — Agent Reference Documentation

Consumer Mode for Agents

  • Assume package is installed from NuGet.
  • Do not rely on repository source code access.
  • Prefer stable public APIs and extension methods documented here.
  • If behavior is uncertain, fail safely and request config/package version details.

Purpose

Genocs.Saga.Integrations.MongoDB replaces the default in-memory saga persistence in Genocs.Saga with durable MongoDB-backed storage for both saga state and saga logs. It exposes two UseMongoPersistence extension methods on ISagaBuilder — one that reads from IConfiguration and one that accepts an explicit SagaMongoOptions object.

Quick Facts

KeyValue
PackageGenocs.Saga.Integrations.MongoDB
Target frameworksnet10.0, net9.0, net8.0
Primary roleMongoDB-backed saga state and log persistence
Typical startup APIsAddSaga + UseMongoPersistence

Install

dotnet add package Genocs.Saga.Integrations.MongoDB

Minimal Integration Recipe (Program.cs)

using Genocs.Saga;
using Genocs.Saga.Integrations.MongoDB;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddSaga(saga =>
{
    saga.UseMongoPersistence(builder.Configuration);
});

var app = builder.Build();
app.Run();

Configuration

Use the sagaMongo section in appsettings.json.

{
  "sagaMongo": {
    "enabled": true,
    "connectionString": "mongodb://localhost:27017",
    "database": "genocs_saga"
  }
}
SettingTypeDescription
connectionStringstringMongoDB connection string for saga persistence. Required.
databasestringDatabase name for saga state and log collections. Required.

Dependencies

  • Genocs.Saga
  • MongoDB.Driver
  • Microsoft.Extensions.Configuration

Troubleshooting

  1. Saga still behaves as if using in-memory persistence after adding this package. Fix: Ensure UseMongoPersistence is called inside the AddSaga(saga => { ... }) builder callback during startup.
  2. Startup throws SagaException while loading saga Mongo settings. Fix: Validate that sagaMongo.connectionString and sagaMongo.database are present and non-empty.
  3. Compensation history is missing or unreadable after a deployment update. Fix: Maintain backward compatibility in serialized saga message and state contracts across versions.