【问题标题】:Bot Framework AutoFac Dependency Issue C# (Multiple Container)Bot Framework AutoFac 依赖问题 C#(多容器)
【发布时间】:2018-07-17 20:52:18
【问题描述】:

在我的应用启动中,我有以下代码来注册我的模块。

Conversation.UpdateContainer(builder =>
            {
                builder.RegisterModule<MyModule>();
            });

我正在使用具有以下代码的 InstrumentedLUIS。

   var builder = new ContainerBuilder();

   builder.Register(c => new BotFrameworkApplicationInsightsInstrumentation(CreateBasicSettings()))
            .Keyed<IBotFrameworkInstrumentation>(InstrumentationType.Basic)
            .SingleInstance();

   builder.Register(c => new BotFrameworkApplicationInsightsInstrumentation(CreateSettingsWithCognitiveServices()))
            .Keyed<IBotFrameworkInstrumentation>(InstrumentationType.Cognitive)
            .SingleInstance();

   _container = builder.Build();

由于上面的代码,我的模块注册丢失了,每次后续调用 bot 时,请求的服务都没有注册,请使用可选的。

由于我不知道最新的Autofac,请任何人指导我吗?

【问题讨论】:

  • 如果您可以提供可重现的样本,这有助于发现和解决问题。

标签: c# botframework autofac azure-language-understanding autofac-configuration


【解决方案1】:

添加 DependencyResolver.SetResolver(new AutofacDependencyResolver(container));在 _container = builder.Build(); 之后虽然这只是解决您问题的一步,但我建议您阅读此per-request lifetime scope

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2020-12-01
    • 2020-09-19
    • 2021-11-27
    • 2020-02-07
    • 2020-06-19
    相关资源
    最近更新 更多