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

后端 未结 2 1483
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:35

    I had a similar issue, but in my case my web application has MVC and WebApi Controllers. I resolved like this:

    using Microsoft.Practices.Unity;
    using System.Web.Http;
    using System.Web.Mvc;
    using Unity.Mvc5;
    
    DependencyResolver.SetResolver(new UnityDependencyResolver(container));
    GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
    

    Where the first line is going to use the MVC DependencyResolver and in the second line I use the WebApi UnityDependencyResolver.

提交回复
热议问题