Casting SimpeInjectorWebApiDependencyRresolver to IDependencResolver

44 views Asked by At

I'm working on an ASP.Net web API project. Recently I've tried to refactor my solution and moving all the code relating to dependency injection to a separate project. I use Simple Injector Integration library as dependency injection solution. There is an IDependencyResolver interface in System.Web.Http.Dependencies which is implemented by SimpleInjectorWebApiDependencResolver. I created a class named ResolutionProvider which is supposed to provide a proper dependency resolver object for GlobalConfiguratiuon.Configuration.DependencyResolver field. The ResolutionProvider class has a method with the following signature and body:

public IDependencyResolver GetResolver()
{
    return new SimpleInjectorWebApiDependencyResolver(_container);
}

The problem is : However SimpleInjectorWebApiDependencyResolver implements IDependencyResolver, I'm getting a compile-time error: Cannot convert expression type SimpleInjectorWebApiDependencyResolver to retun type IDependencyResolver. I have tried to cast the class to its interface without no success.

Question:
What is the problem?

1

There are 1 answers

1
Steven On BEST ANSWER

You should take a very good look at the compile error. The most likely cause is that the IDependencyResolver that your method returns is the System.Web.Mvc.IDependencyResolver and not the System.Web.Http.Dependencies.IDependencyResolver.