如何使用Autofac初始化自己的组件? [英] How to use Autofac to initialize your own components?

查看:153
本文介绍了如何使用Autofac初始化自己的组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的bot应用程序(基于BotFramework)中使用Autofac IOC容器.

I would like to use Autofac IOC container in my bot application (based on BotFramework).

我可以看到框架本身已经在使用它.

I can see that framework itself already uses it.

但是我无法弄清楚如何优雅地实现它……我不想在每次调用后解析我的组件(这会减慢我的post方法的执行速度).

But I can't figure out how to do it gracefully... I don't want to resolve my components on every post invocation (it will slow down my post method execution).

非常感谢您与您的解决方案共享代码段.

I appreciate if you share code snippets with your solutions.

提前谢谢!

推荐答案

您可以使用Global.asax框架中使用的Autofac容器并执行自己的注册.

You can use the Autofac container being used in the framework in the Global.asax and perform your own registrations.

关键代码段是:

var builder = new ContainerBuilder();

// perform your registrations on the builder

// update the container being used by the framework
builder.Update(Conversation.Container);

要真正执行此操作,可以查看 Global.asax 此处实际的模块.

For a real implementation of this, you could take a look to the ContosoFlowers sample where you will see that a Module is used to register the application specific components. Here is the Global.asax and here the actual module.

这篇关于如何使用Autofac初始化自己的组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆