我已经设置了一个非常简单的依赖解析器,但我的控制器没有调用它。
当我点击 HomeController GetService 被调用时:( http:localhost:xxxx/ )但(http://localhost:xxxx/api/Customers)它不是。
在 Global.asax 我已经把 Application_Start
DependencyResolver.SetResolver(new PoorMansResolver());
我的解析器类是
public class PoorMansResolver : IDependencyResolver
{
static readonly ICustomerRepository CustomerRepository = new CustomerRepository();
public object GetService(Type serviceType)
{
if (serviceType == typeof (CustomersController))
return new CustomersController(CustomerRepository);
else return null;
}
public IEnumerable<object> GetServices(Type serviceType)
{
return new List<object>();
}
}
为什么不调用解析器?