MVC WebApi not using AutofacWebApiDependencyResolver

后端 未结 2 857
北荒
北荒 2021-02-14 09:40

I have a mixed MVC 4 app, where some controllers are regular implementations of Controller and some controllers are implementations of ApiController.

相关标签:
2条回答
  • 2021-02-14 10:13

    To setup Autofac for Web.API you need to do two things:

    1. Register the Autofac dependency resolver (in the App_Start):

      GlobalConfiguration.Configuration.DependencyResolver = 
          new AutofacWebApiDependencyResolver(container);
      
    2. And register your Api controllers in your container builder with the call:

      containerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
      
    0 讨论(0)
  • 2021-02-14 10:33

    Probably this blog can help you: http://blogs.msdn.com/b/roncain/archive/2012/07/16/dependency-injection-with-asp-net-web-api-and-autofac.aspx

    0 讨论(0)
提交回复
热议问题