2

I used to have a standard ASP.NET MVC 3 application that was Ninject-wired via WebActivators preAppStart hook. My controllers were dependency injected via constructor injection - classic.

However not I need to handle some request via .ashx web handler. As know from several discussions here on SO, the only way to inject into a handler is via service locator instance.

What if I need to inject exactly an instance that was instanciated in Ninject kernel for Controllers?

My ISessionChecker is bound to an XmlSessionChecker in Singleton scope in ninject module and the module is loaded into kernel and the kernel is in bootstraped into an ASP.NET MVC application at app_start.

Now I need my handlers to be locating this very same instance of XmlSessionChecker from global kernel. Can I somehow get this kernel as a service locator?

1 Answer 1

1

Well, it turns out I could just use System.Web.Mvc.DependencyResolver.Current.GetService to locate my dependency, as I would in any other MVC 3 app's code.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. You saved my day. I've been looking for a solution to this for hours. Till I found yours :)

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.