Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register all autofac modules from assembly by one line

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

builder.RegisterModule(new LoggingInjectionModule());

But if I have 10 or more modules I want just to specify assembly, where Autofac can find all modules, that it need to register. Is there is any way to register all modules from specific assembly, namespace by single line or two lines?

like image 320
user809808 Avatar asked Nov 23 '13 07:11

user809808


1 Answers

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

builder.RegisterAssemblyModules(Assembly.GetExecutingAssembly());
like image 102
nemesv Avatar answered Sep 22 '22 09:09

nemesv