【发布时间】:2020-04-24 09:35:21
【问题描述】:
是否有用于 StructureMap 的 ISagaDbContextFactory 实现?我已经看到了 Autofac 的 AutofacSagaDbContextFactory 实现,我会为 StructureMap 编写自己的实现,但我不知道要寻找什么有效负载来获取 nested 的实例我希望masstransit 创建的strong> 容器?我尝试了以下没有运气
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 在我的容器中注册为作用域,因此希望每个 saga 实例作用域都有一个新实例,即,如果它是一个 Web 应用程序,则类似于每个 Web 请求的 DbContext 实例,但在此实例中适用于 masstransit saga。
更新:ContainerSagaDbContextFactory 类解决了我的问题。
【问题讨论】:
标签: entity-framework structuremap masstransit saga