4

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?

2 Answers 2

1

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!

1
  • +1 the linked answer its not exactly property injection, but using service locator would be another approach. I still prefer the earlier.
    – eglasius
    Commented Sep 25, 2010 at 15:40
1

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.

1
  • Is there any more detail you could give, I'm at a loss where to start. Commented Sep 25, 2010 at 4:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.