WebApi.UnityDependencyResolver does not implement Microsoft.Practices.ServiceLocation.IServiceLocator. Parameter : commonServiceLocator

后端 未结 2 1482
Happy的楠姐
Happy的楠姐 2021-02-20 09:54

I try to run the following code:

using System.Web.Http;
using System.Web.Mvc;
using Conduit.Mam.ClientSerivces.Dal.Configuration;
using MamInfrastructure.Common.         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-20 10:43

    In your Initialize method replace:

    GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
    

    with:

    GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
    

    Now you understand what the problem is:

    System.Web.Http.Dependencies.IDependencyResolver (used by the Web API) and System.web.Mvc.IDependencyResolver (used by ASP.NET MVC) are two completely different types (even if they have the same name) and yet you attempt to assign both of them to the same type (UnityDependencyResolver) which obviously cannot work.

提交回复
热议问题