MongoDB¶
To use MongoDB - Saga Store
integration, the NuGet package CrystalSharp.MongoDb
must be installed.
IMPORTANT
Kindly keep in mind that this particular configuration is intended for the purpose of storing transaction states in the saga store. However, the configuration procedures for database integration, Event Store, and Read Model Store will be approached differently.
Saga Store Registration¶
Registration for the saga store implementation is required. Following is the code that illustrates how to register the implementation of the saga store in the Program.cs
file:
MongoDbSettings mongoDbSagaStoreSettings = new("CONNECTION-STRING", "DATABASE");
CrystalSharpAdapter.New(builder.Services)
.AddCqrs(typeof(CreateCategoryCommandHandler))
.AddMongoDbSagaStore(mongoDbSagaStoreSettings, typeof(PlaceOrderTransaction))
.CreateResolver();
In the above code snippet, when initializing the Crystal Sharp framework, a call to an extension method is made AddMongoDbSagaStore(mongoDbSagaStoreSettings, typeof(PlaceOrderTransaction))
for the saga store registration. The parameter typeof(PlaceOrderTransaction)
scans the assembly where saga transactions, saga transaction handlers, saga locators, and saga implementations reside and registers them.