[英]Autofac Resolving MatchingLifetimeScope Collection
我想從命名范圍解析所有服務的 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.