-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ken
committed
Jan 15, 2024
1 parent
8d3bea1
commit 80ff0e9
Showing
2 changed files
with
14 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
src/MinimalDomainEvents.Outbox.MongoDb/IOutboxDispatcherBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MinimalDomainEvents.Outbox.Abstractions; | ||
using MongoDB.Bson.Serialization; | ||
using MongoDB.Driver; | ||
|
||
namespace MinimalDomainEvents.Outbox.MongoDb; | ||
public static class IOutboxDispatcherBuilderExtensions | ||
{ | ||
public static IOutboxDispatcherBuilder AddMongo(this IOutboxDispatcherBuilder builder, MongoClient mongoClient) | ||
{ | ||
TryRegisterOutboxRecordClassMap(); | ||
builder.Services.AddScoped<IPersistOutboxRecords>(sp => ActivatorUtilities.CreateInstance<MongoDbDomainEventPersister>(sp, builder.OutboxSettings, mongoClient)); | ||
return builder; | ||
} | ||
|
||
public static IOutboxDispatcherBuilder AddMongo(this IOutboxDispatcherBuilder builder, Func<IServiceProvider, MongoClient> mongoClientFactory) | ||
{ | ||
TryRegisterOutboxRecordClassMap(); | ||
builder.Services.AddScoped<IPersistOutboxRecords>(sp => ActivatorUtilities.CreateInstance<MongoDbDomainEventPersister>(sp, builder.OutboxSettings, mongoClientFactory(sp))); | ||
return builder; | ||
} | ||
|
||
private static bool TryRegisterOutboxRecordClassMap() | ||
{ | ||
return BsonClassMap.TryRegisterClassMap<OutboxRecord>(cm => | ||
{ | ||
cm.AutoMap(); | ||
cm.SetIgnoreExtraElements(true); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters