We are running a webforms project at my company and I have an HttpModule that I need to resolve dependencies for.
We use the Ninject.Web library to resolve dependencies for master pages, pages, user controls, web services, and HttpHandlers. All these have base classes you can inherit from in the Ninject.Web Namespace:
- MasterPageBase
- PageBase
- WebServiceBase
- HttpHandlerBase
- And a custom one we added since for some odd reason it wasn’t there: UserControlBase
However I am unable to find a HttpModuleBase. There is a NinjectHttpModule, but that is not a base class, it is a real module that tries to eliminate the need to inherit from base classes in pages and user controls, but it has some bugs and we are not using it.
What is the best way to resolve my dependencies in my HttpModule?
When I google this I come up with this question on the first page -_-
I’m kind of amazed that nobody has answered this all day! Looks like I stumped you guys 🙂
Well, I solved the issue. I wrote my own custom implementation of
IHttpModuleand compiled it into the Ninject.Web assembly myself. Here is the source of the base class I added:I simply modeled it after the other base classes in the Ninject.Web assembly. It appears to be working wonderfully. Just make your HttpModule inherit from
Ninject.Web.HttpModuleBaseand then you are free to use property injection within your module, like this: