views:

60

answers:

2

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?

A: 

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.

eglasius
Is there any more detail you could give, I'm at a loss where to start.
Christopher Edwards
+1  A: 

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!

adrift
+1 the linked answer its not exactly property injection, but using service locator would be another approach. I still prefer the earlier.
eglasius