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