Call all instances of ISomething in Autofac

I have an ISomething interface with the Start method. I want to get all implementations of this interface (in several assemblies, main and all referenced) and call the Start method when the application starts. How can I do this with Autofac 2.4.4.705?

+3
autofac
source share
1 answer

you can decide

IEnumerable<ISomething> 

and call Start for each of them

I forgot to note that you must 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 from which you want to register.

+8
source share

All Articles