Autofac with MVC4: controller does not have a default constructor

懵懂的女人 提交于 2019-12-04 23:19:06

With the RegisterApiControllers method you tell Autofac where (in which assembly) it should look for your ApiControllers

So the following call:

builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

Registers the ApiControllers from the current assembly (project).

If you have ApiControllers also in a different project you need to use it like this:

builder.RegisterApiControllers(typeof(UserController).Assembly);

Which means: register all the ApiController form the assembly (project) where the UserController lives. So you only need one RegisterApiControllers per assembly even if you have multiple ApiController in an assembly (project).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!