我有一个由DefaultFoo实现的IFoo服务,并且已经在autofac容器中注册了它.
I have an IFoo service implemented by DefaultFoo, and I've registered it as such in my autofac container.
现在,我想允许IFoo的替代实现在插件程序集中实现,可以将其放置在"plugins"文件夹中.如果存在,我如何配置autofac使其更喜欢这种替代实现?
Now I would like to allow for an alternative implementation of IFoo to be implemented in a plugin assembly, which can be dropped in a "plugins" folder. How do I configure autofac to prefer this alternative implementation if it is present?
推荐答案如果您注册了一些接口实现,则Autofac将使用最新的注册.其他注册将被覆盖.对于您而言,如果插件存在,Autofac将使用插件注册并注册自己的IFoo服务实现.
If you register some interface implementations, Autofac will use the latest registration. Other registrations will be overridden. In your case, Autofac will use the plugin registration, if plugin exists and register own IFoo service implementation.
如果有多个组件公开同一服务,则Autofac将使用最后注册的组件作为该服务的默认提供程序.
If more than one component exposes the same service, Autofac will use the last registered component as the default provider of that service.
请参见默认注册
更多推荐
使用插件覆盖autofac注册
发布评论