I am building a REST API with ASP.NET WebAPI. Everything worked fine, but then I came up with the great idea to use interfaces in all my method calls. After I have changed all the methods i noticed that after setting the parameter in my Controller methods as interfaces, my API calls does not work. I am using OWIN Self host and Unity dependency injection. Here is my relevant code:
Resolving my Interface:
IUnityContainer container = new UnityContainer();
container.RegisterType<IMyInterface, MyInterfaceImpl>(new HierarchicalLifetimeManager());
HttpConfiguration config = new HttpConfiguration();
config.DependencyResolver = new UnityDependencyResolver(container);
My Controller (the part where i get the error)
[Route("test")]
[HttpGet]
public HttpResponseMessage GetSomeData([FromUri]IMyInterface searchObject)
{
return this._searchService.SearchForData(searchObject);
}
When calling this method i get the error that an interface cannot be created. I unterstand that, but the problem is fixing it. I looked at ASP.NET Web API Operation with interfaces instead concrete class and also at https://brettedotnet.wordpress.com/2014/07/16/web-api-and-interface-parameters/ and at ASP.NET Web API Operation with interfaces instead concrete class, but none of the suggestions worked in my case (always getting the error that an interface cannot be created).
I was wondering if someone has a working example on something like this(on github or elsewhere) just to check what I am doing wrong (or even an idea what else I could try would be nice)
Thank you