【问题标题】:Autofac configuration problems trying to integrate Quartz尝试集成 Quartz 的 Autofac 配置问题
【发布时间】: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


    【解决方案1】:

    好的,我明白了。需要这条线:

    builder.RegisterType<DataContext>().InstancePerOwned<EmailAllocationJob>()
        .As<IUnitOfWork>().AsSelf();
    

    因此,DataContext 作为 RegisterType ONCE 的通用参数似乎很重要,并且对 As() 和 AsSelf() 的方法调用将菊花链式连接在单个语句中。现在看起来很明显,昨天晚上有了新的头脑。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-08
      • 2018-07-09
      • 1970-01-01
      • 2016-07-05
      相关资源
      最近更新 更多