使用插件覆盖autofac注册

编程入门 行业动态 更新时间:2024-10-26 13:32:23
本文介绍了使用插件覆盖autofac注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个由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注册

本文发布于:2023-11-04 12:29:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   autofac

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!