c# - Autofac 解析匹配LifetimeScope 集合
问题描述
我想从命名范围解析所有服务的 IEnumerable,但这不起作用,因为服务也从其他命名范围解析。
例子
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterType<B>().As<IMyInterface>().InstancePerMatchingLifetimeScope("B");
containerBuilder.RegisterType<A>().As<IMyInterface>().InstancePerMatchingLifetimeScope("A");
IContainer container= containerBuilder.Build();
ILifetimeScope lifetimeScope = container.BeginLifetimeScope("A");
lifetimeScope.Resolve<IEnumerable<IMyInterface>>();
投掷 DependencyResolutionException: Unable to resolve the type 'ConsoleApp2.B' because the lifetime scope it belongs in can't be located.
有没有办法只解决当前范围内的服务?
我正在使用Autofac 6.0.0
解决方案
看来您遇到了错误。 有一个类似的问题已经解决了;我会将您的特定案例的重现添加到问题中,并将其更新为标记为错误而不是增强。
我目前不知道任何解决此问题的解决方法。对不起。
推荐阅读
- wordpress - 过滤器应用于意外查询
- java - 在 Azure 搜索上上传文档后,我可以查询它吗?
- pact - 如何处理 Pact 上的多态端点?
- r - 如何修复 R 中的“找不到对象”错误
- qt - 如何在 Qt 5.12 中使用 /std:c++latest
- linux - 为什么我的 Raspberry Pi SPI 写入循环会暂停大约 15 毫秒?上下文切换?
- html - 如何修复这个第二层下拉菜单背景?
- routing - Angular6:将数据从导航头传递到路由组件
- javascript - 如何在角度 onInit 方法中测试订阅功能?
- angular - ngClass 不影响任何东西