【发布时间】:2013-05-22 16:30:29
【问题描述】:
我正在使用此处找到的 Owned 类型:Strong reference of Autofac 2
我也在使用 Quartz 调度程序、MSMQ 和 EF。
我的配置如下所示。我显然有问题,因为注入到存储库的上下文与提供给服务的实例不同。
builder.RegisterType<EmailAllocationJob>();
builder.RegisterGeneric(typeof(JobWrapper<>));
builder.RegisterType<DataContext>().InstancePerOwned<EmailAllocationJob>();
builder.RegisterType<DataContext>().As<IUnitOfWork>();
builder.RegisterType<EmailAccountRepository>().As<IEmailAccountRepository>();
builder.RegisterType<EmailMessageRepository>().As<IEmailMessageRepository>();
builder.RegisterType<EmailMessageQueue>().As<IEmailMessageQueue>();
builder.RegisterType<EmailAllocationService>().As<IEmailAllocationService>();
我这辈子都不知道如何修复配置。我估计是这条线:
builder.RegisterType<DataContext>().As<IUnitOfWork>();
我想说的是:
builder.RegisterType<DataContext>().As<IUnitOfWork>().InstancePerOwned<EmailAllocationJob>();
如果您能提供帮助,请提前致谢。
【问题讨论】:
标签: entity-framework ioc-container quartz-scheduler autofac