Hi,
I am working on getting Funq working as a IDependencyResolver with WebApi (long story). I am using the documented WebApi IDependencyResolver to do this, but for some reason, whenever WebApi tries to resolve any ApiController, I am getting the following exception:
Value cannot be null.
Parameter name: value
at System.Web.Http.Controllers.HttpControllerContext.set_Configuration(HttpConfiguration value)
at lambda_method(Closure , Container )
at Funq.Container.ResolveImpl[TService](String name, Boolean throwIfMissing)
The IDependencyResolver implementation looks like (this was bastardised from a post for MVC which has a slighlty different signature and the Cache.CreateInstance also differed in it didn’t expect an IResolver as it’s first param. I can’t find too much about this level of detail, but can you see anything wrong with this?
I have tried with BeginScope() returning a Funq child, but am out of ideas.
public class FunqDependencyResolver : IDependencyResolver
{
private readonly ContainerResolveCache cache;
private readonly Container container;
public FunqDependencyResolver(Container container)
{
this.cache = new ContainerResolveCache(container);
this.container = container;
}
public object GetService(Type serviceType)
{
try
{
return this.cache.CreateInstance(this.container, serviceType, true);
}
catch (Exception ex)
{
return null;
}
}
public IEnumerable<object> GetServices(Type serviceType)
{
return Enumerable.Empty<object>();
}
public IDependencyScope BeginScope()
{
return this;
}
public void Dispose()
{
container.Dispose();
}
}