Christopher Edwards
Christopher Edwards

Reputation: 6659

Using Dependency Injection with Http Handlers

I am using ASP.NET MVC 2 with Ninject, and Linq2SQL behind a repository pattern, based on Rob Conery's TekPub Starter Site.

With controllers it all works fine, however I have an HTTP Handler (it serves and resizes images from a DB), and I have no idea how I use Ninject to replace my ISession interface with a concrete instance of my LinqToSQLSession.

How should I best do this?

Upvotes: 4

Views: 3285

Answers (2)

eglasius
eglasius

Reputation: 36037

Use property injection. I have used it with StructureMap, but Ninject should support it

Define a base class for your http handlers, and hook DI in there.

Update:

Check here for what's property injection vs. other types of injection: http://wiki.github.com/ninject/ninject/injection-patterns

In the base class for the handlers you need to get a hold of your ninject IKernel instance and call .Inject(this) on initialization.

Upvotes: 1

Jeff Ogata
Jeff Ogata

Reputation: 57783

This SO question is about using ninject w/ HttpHandlers: HttpHandler Property Injection using Ninject returning null

Wish I could give you a better answer, but hopefully that will be enough to get you going. Good luck!

Upvotes: 1

Related Questions