I've started playing around with the new ASP.Net Web Api (available as part of MVC 4), and was completely stumped as to why the GetService method on IDependencyResolver was not being called when my API controller was being requested.
Controllers that were derived from Controller, GetService was called, however any controller deriving from ApiController GetService was not being fired (resulting in the No parameterless constructor defined for this object exception being thrown).
Little did I know, IDependencyResolver for ApiControllers is a completely different type and is 'set' on a different resolver.
Web API: System.Web.Http.Services.IDependencyResolver
Http: System.Web.Mvc.IDependencyResolver
And for setting the resolver for ApiControllers, it should be done as GlobalConfiguration.Configuration.ServiceResolver.SetResolver()
Rather than DependencyResolver.SetResolver()
No comments:
Post a Comment