gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 07:45:38 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com