the Outbox is not influenced by the RegisterComponents call. If the Outbox is enabled in the endpoint configuration, it’ll be used. In this case, the outbox will use (and control) the same connection and transaction that the example uses to create the Entity Framework data context instance. As shown, it’s essential your code uses the connection and transaction from the ISqlStorageSession instance.
Great. But is this the recommended way to integrate the Outbox pattern with EF? Instead of creating a custom EF DbContextFactory and connecting with the ISqlStorageSession as described here
Conceptually, they are doing the same thing. The following piece of code:
COPY CODE|COPY USINGS|EDIT
endpointConfiguration.RegisterComponents(c =>
{
c.AddScoped(b =>
{
var session = b.GetRequiredService<ISqlStorageSession>();
var context = new ReceiverDataContext(session.Connection);
//Use the same underlying ADO.NET transaction
context.Database.UseTransaction(session.Transaction);
//Ensure context is flushed before the transaction is committed
session.OnSaveChanges((s, cancellationToken) => context.SaveChangesAsync(cancellationToken));
return context;
});
});