Will the "Entity Framework integration with SQL Persistence" also include Outbox?

I have read the section “Unit of work” here Entity Framework integration with SQL Persistence • Sql Persistence Samples • Particular Docs

Does the RegisterComponents also ensures that if Outbox is enabled, that this is participating in the same transaction as EF DbContext?

Hu, @Stig_Christensen.

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.

.m

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;
    });
});

Is the context factory.