ASP.Net MVC 4 Web API controller doesn't work with Unity.WebApi

前端 未结 2 1078
温柔的废话
温柔的废话 2020-12-17 19:28

My ASP.Net MVC 4 Web API controller doesn\'t work with Unity.WebApi. In the same project simple controllers works with Unity.Mvc3 properly. But when I run Web API controller

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 19:51

    When you install Unity for ASP.NET Web API, it does everything except add the following line to your Global.asax

    Bootstrapper.Initialise();
    

    So you need to add that to your Application_Start method:

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
    
        Bootstrapper.Initialise();
    
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }
    

提交回复
热议问题