c# - 使用插件覆盖 autofac 注册

标签 c# dependency-injection autofac

我有一个由 DefaultFoo 实现的 IFoo 服务,我已经在我的 autofac 容器中注册了它。

现在我想允许在插件程序集中实现 IFoo 的替代实现,它可以放在“plugins”文件夹中。如果 autofac 存在,我该如何配置它以更喜欢这种替代实现?

最佳答案

如果你注册了一些接口(interface)实现,Autofac会使用最新的注册。其他注册将被覆盖。在您的情况下,Autofac 将使用插件注册,如果插件存在并注册自己的 IFoo 服务实现。

If more than one component exposes the same service, Autofac will use the last registered component as the default provider of that service.

参见 Default Registrations

关于c# - 使用插件覆盖 autofac 注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15754702/

相关文章:

java - Spring - Bean 创建中的 StackOverflowError

c# - Autofac 异常 : Cannot resolve parameter of constructor 'Void . 构造函数

c# - 接口(interface)方法上的 CreateDelegate

c# - 如何在特殊条件下使用 C# 中的正则表达式突出显示关键字?

c# - C# 中插入符位置、字符串长度和匹配索引不一致

dependency-injection - Jersy2注入(inject)slf4j记录器

c# - 使用 Ninject 进行深度大于 1 的上下文/条件依赖注入(inject)?

c# - 使用 Autofac KeyFilterAttibute 将服务注入(inject) Action Filter

autofac - 容器构建时激活 SingleInstance

c# - 以编程方式批准/拒绝工作流程并添加评论