I have an ASP.NET core application built with the Domain-Driven-Design concept implemented through MediatR. My application saves data to Azure Cosmos DB. I need to raise integration events from my ASP.NET Core application. I'm looking to use NServiceBus.Persistence.CosmosDB with Outbox. However, it seems that the NServiceBus outbox can only work inside the NServiceBus handler.
See: https://discuss.particular.net/t/outbox-in-an-asp-net-core-scenario/966
From the above thread, it appears that we can achieve this with Sql Server. However, I'm looking to get it working with Cosmos DB. Has anyone been able to successfully implement the Outbox pattern using NServiceBus in the ASP.NET Core web application? Any pointers, is highly appreciated.
With the introduction of the NServiceBus.TransactionalSession package it is now possible to use the outbox outside the context of a handler. The previous restrictions no longer apply.
The NServiceBus.Persistence.CosmosDB.TransactionalSession package provides integration with NServiceBus.Persistence.CosmosDB. The "Using Transactional Session with CosmosDB" sample shows to to integrate the transactional session with CosmosDB while the "Using TransactionalSession with Entity Framework and ASP.NET Core" show how to integrate a middleware into ASP.NET Core that manages the opening and committing of the session.