错误:
Unity.WebApi.UnityDependencyResolver 类型似乎没有实现 Microsoft.Practices.ServiceLocation.IServiceLocator。
我看到了这个问题WebApi.UnityDependencyResolver does not implement Microsoft.Practices.ServiceLocation.IServiceLocator。参数:commonServiceLocator,但我的错误在这一行:
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
完整的课程:
public static class Bootstrapper
{
public static void Initialise()
{
var container = BuildUnityContainer();
DependencyResolver.SetResolver(new UnityDependencyResolver(container)); // <-- error
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
}
private static IUnityContainer BuildUnityContainer()
{
var container = new UnityContainer();
container.RegisterType<IAutenticacionDbContext, AutenticacionDbContext>();
return container;
}
}
注意:有了这个我得到同样的错误:
var container = BuildUnityContainer();
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
DependencyResolver.SetResolver(new UnityDependencyResolver(container));