如何在果园中注册自定义生成Autofac.Module? [英] How to register custom build Autofac.Module in Orchard?

查看:211
本文介绍了如何在果园中注册自定义生成Autofac.Module?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码封装了不是Orchard特有的功能.但是我需要通过依赖注入使它在Orchard中可用.因此,我建立了一个注册所有组件(类型)的Autofac模块,但是我找不到一种方法来通知Orchard的Autofac容器.

I have a piece of code that encapsulates functionality that isn't specific to Orchard. However i need to make it available in Orchard via dependency injection. So, I built up an Autofac Module that registers all components (types), but I can't find a way to inform Orchard's Autofac Container about it.

根据我的说法,有两种方法可以将模块添加到容器中:

From what i red, there are two ways to add a module to a container:

通过将模块提供给ContainerBuilder(通常在启动时), 或通过在运行时使用ContainerBuilder更新已构建的Container

By supplying the module at to the ContainerBuilder (usually at start-up), Or by updating the already built Container at runtime with a ContainerBuilder

我可以用第一种方法解决问题,但是如果存在这种情况,我宁愿改用第二种方法?

I can approach the problem in the first way, but I rather do a variant of the second if there is such?

推荐答案

只需将派生自Autofac.Module的类添加到您的Orchard模块即可. Orchard会在容器构建过程中自动选择它.

Just add a class deriving from Autofac.Module to your Orchard module and that's it. It will get automatically picked by Orchard during the container construction.

这篇关于如何在果园中注册自定义生成Autofac.Module?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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