Is there an implementation of ISagaDbContextFactory for StructureMap? I've seen an implementation of AutofacSagaDbContextFactory for Autofac, and I would write my own for StructureMap, but I don't know what payload to look for to get an instance of the nested container that I would have expected masstransit to have created?? I tried the following with no luck
public class StructureMapSagaDbContextFactory<TSaga> : ISagaDbContextFactory<TSaga> where TSaga : class, ISaga
{
...
public DbContext CreateScoped<T>(ConsumeContext<T> context) where T : class
{
if (context.TryGetPayload(out IContainer container)) // I don't know what to look for in the payload
return currentScope.GetInstance<MyDbContext>();
return Create();
}
...
}
MyDbContext is registered as scoped with my container, and so would like a new instance per saga instance scope, i.e. similar to DbContext instance per web request if it were a web app, but for masstransit saga in this instance.
UPDATE: The ContainerSagaDbContextFactory class solved my problem.