I just converted an MVC 4 project to MVC 5 beta (and a Web Api project to Web Api 2) and I'm having some issues with DependencyResolver
not being able to resolve the class I need.
Here is the class I want to resolve:
public class GetPartsQueryValidationHandler
: IQueryValidationHandler<GetPartsQuery, Part[]>
{
...
}
Here is how I register it with Autofac in Bootstrapper.cs ( I do this in both projects):
builder.RegisterAssemblyTypes(dataAccessAssembly)
.AsClosedTypesOf(typeof(IQueryValidationHandler<,>))
.InstancePerHttpRequest(); //..PerApiRequest in Web Api
I also register the DependencyResolver in both projects :
In Mvc Project:
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
In Web Api Project:
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
Then in a third project I call the following to resolve the reference:
var handlerType = typeof(IQueryValidationHandler<,>).MakeGenericType(query.GetType(), typeof(TResult));
dynamic handler = DependencyResolver.Current.GetService(handlerType);
But this gives me a null handler
I need to resolve that class somehow.