本文介绍了调用Autofac中的所有ISomething实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个接口ISomething,带有启动方法.我想获取此接口的所有实现(在多个程序集中,在主要程序集和所有引用的程序集中),并在应用程序启动时调用Start方法.如何使用Autofac 2.4.4.705做到这一点?
I have an interface ISomething with a method Start.I want to get all implementations of this interface (in multiple assemblies, the main one and all referenced ones) and call the Start method on application start.How can I do this with Autofac 2.4.4.705?
推荐答案
您可以解决
IEnumerable<ISomething>
并为每个电话呼叫开始"
and call Start for each of them
忘记了,您应该首先注册ISomething的所有实现.
Forgot to mention, that you should first register all implementations of ISomething.
Assembly[] assemblies = ...;
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(assemblies).AssignableTo<ISomething>().As<ISomething>();
var container = builder.Build();
程序集"是您要从中注册的程序集数组.
Where "assemblies" is an array of assemblies you want to register from.
这篇关于调用Autofac中的所有ISomething实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!