Autofac - dependency injection for MVC controller and Web Api controller

前端 未结 1 2023
说谎
说谎 2021-01-20 00:17

I have MVC controllers (in Controllers folder) and Web Api controllers (in Api folder) in the same project: Here is the folder structure:

  • Controllers
相关标签:
1条回答
  • 2021-01-20 00:31

    You haven't set Web API's GlobalConfiguration.Configuration.DependencyResolver; you only set MVC's DependencyResolver.

    Add the following line:

    GlobalConfiguration.Configuration.DependencyResolver =
        new AutofacWebApiDependencyResolver(container);
    
    0 讨论(0)
提交回复
热议问题