Register all autofac modules from assembly on one line

I can register all Autofac modules (classes derived from Autofac.Module) one by one using a string like

builder.RegisterModule(new LoggingInjectionModule());

But if I have 10 or more modules, I just want to specify the assembly where Autofac can find all the modules that need to be registered. Is there a way to register all modules from a particular assembly, namespace on one line or two lines?

+6
source share
1 answer

You can use various overloads (see API doc ) of the RegisterAssemblyModules method:

 builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly()); 
+8
source

Source: https://habr.com/ru/post/958689/


All Articles