0

I have a Self Host ASP.net WEB API v.4.0.20710.0, that is a legacy package which I got via NuGet.

So my question is if it is possible to get an reference of my logging class to a controller, because they seem to get instanciated somewhere in external code that I can not access.

The only possible solution I see is to make the logging class static, but that would be really uncomfortable. Any other ideas?

Marv
  • 119
  • 3
  • 14
  • 1
    Please read [ask] and share your research. You're looking for something called "dependency injection", and there's been written plenty about that subject. See for example [Using WebApi and structure map dependency injection](http://stackoverflow.com/questions/15497355/using-webapi-and-structure-map-dependency-injection). – CodeCaster May 17 '16 at 13:50
  • @CodeCaster Thank you but that seems not to be quite the answer, mabye I just don't get it through. I am using .net 4.0 and therefore it seems that I dont have access to that GlobalConfiguration – Marv May 17 '16 at 14:23
  • 1
    If you mean you use WebAPI 1, you'll have some class like `WebApiConfig` with a method `Register(HttpConfiguration config)`, where you can access `config.DependencyResolver`. – CodeCaster May 17 '16 at 14:29

0 Answers0