Skip to content

feat: MongoDB outbox repository (NetEvolve.Pulse.MongoDB)#425

Merged
samtrion merged 5 commits intomainfrom
copilot/add-mongodb-outbox-repository
Apr 20, 2026
Merged

feat: MongoDB outbox repository (NetEvolve.Pulse.MongoDB)#425
samtrion merged 5 commits intomainfrom
copilot/add-mongodb-outbox-repository

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

Adds NetEvolve.Pulse.MongoDB — a MongoDB-backed IOutboxRepository for teams using MongoDB as their primary data store, enabling the outbox to coexist in the same database as domain aggregates without introducing a relational dependency.

New Package

  • MongoDbOutboxRepository : IOutboxRepository — full async MongoDB driver implementation. Pending/failed message claiming uses FindOneAndUpdateAsync in a loop (sorted by CreatedAt) for atomic, concurrent-safe batch acquisition.
  • MongoDbOutboxOptionsDatabaseName (required) and CollectionName (default: outbox_messages).
  • MongoDbExtensions — two registration patterns on IMediatorBuilder:
    • AddMongoDbOutbox(...) — registers core outbox services + MongoDB repository in one call.
    • UseMongoDbOutbox(...) — provider-swap for when AddOutbox() was already called.
  • IMongoClient must be pre-registered in DI by the caller.
  • Health check implemented via MongoDB ping command.
  • OutboxDocument maps OutboxMessage fields via [BsonId]/[BsonElement]; DateTimeOffset stored as UTC DateTime to avoid BSON representation ambiguity.

Usage

// Register IMongoClient first (caller's responsibility)
services.AddSingleton<IMongoClient>(new MongoClient(connectionString));

services.AddPulse(config => config
    .AddMongoDbOutbox(opts =>
    {
        opts.DatabaseName = "myapp";
        opts.CollectionName = "outbox_messages"; // optional, this is the default
    }));

Infrastructure

  • MongoDB.Driver 3.0.0 added to Directory.Packages.props.
  • Testcontainers.MongoDb 4.11.0 added for integration tests.
  • DatabaseType.MongoDB added to the shared enum.
  • Unit tests cover constructor validation and DI registration (avoids Mock.Of<IMongoClient>() due to TUnit.Mocks source-generator limitations with MongoDB.Driver's complex generic interfaces — uses new MongoClient(...) directly instead).
  • Integration tests use MongoDbContainerFixture (shared Testcontainers instance) with per-test collection isolation via OutboxOptions.TableName → MongoDbOutboxOptions.CollectionName bridging.

Copilot AI linked an issue Apr 18, 2026 that may be closed by this pull request
7 tasks
Copilot AI changed the title [WIP] Add MongoDB-backed outbox repository implementation feat: MongoDB outbox repository (NetEvolve.Pulse.MongoDB) Apr 18, 2026
Copilot AI requested a review from samtrion April 18, 2026 06:17
@samtrion samtrion marked this pull request as ready for review April 18, 2026 10:53
@samtrion samtrion force-pushed the copilot/add-mongodb-outbox-repository branch from c09633d to 83785f9 Compare April 18, 2026 10:53
@samtrion samtrion requested review from a team as code owners April 18, 2026 10:53
@samtrion samtrion force-pushed the copilot/add-mongodb-outbox-repository branch from 83785f9 to 4f5005e Compare April 19, 2026 19:33
@samtrion samtrion force-pushed the copilot/add-mongodb-outbox-repository branch from 4f5005e to dd25569 Compare April 20, 2026 09:39
Generalize IDatabaseInitializer to IServiceInitializer across all test infra, updating all usages and parameter names for consistency. Add MongoDbOutboxManagement for dead-letter and statistics support, and register IOutboxManagement in MongoDbExtensions. Simplify Redis idempotency test assertions and update MongoDbOutboxTests verified output.
Extract repeated $sum/$cond aggregation logic for OutboxMessageStatus counting into a new StatusCountField method. This reduces code duplication and improves maintainability of the aggregation pipeline.
Extract conversion methods between OutboxDocument and OutboxMessage into a new static OutboxDocumentMapper class. Update MongoDbOutboxRepository and MongoDbOutboxManagement to use this mapper and remove redundant private conversion methods, improving code reuse and maintainability.
Removed unnecessary <DateTime?> generics from MongoDB filter expressions for NextRetryAt, streamlining the code. Improved XML documentation in OutboxDocument.cs by removing redundant namespace qualifications and clarifying date/time storage and conversion details.
@samtrion samtrion merged commit f60389c into main Apr 20, 2026
8 of 9 checks passed
@samtrion samtrion deleted the copilot/add-mongodb-outbox-repository branch April 20, 2026 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: MongoDB outbox repository (NetEvolve.Pulse.MongoDB)

2 participants