ninject/Ninject.Web.Mvc

Add ActionResult invoker

danieltian opened this issue · 3 comments

I noticed that Ninject.Web.Mvc has an ActionFilter invoker, to inject dependencies into an ActionFilter. Is it possible to do the same for ActionResults?

As ActionResults are created in Actions of a controller you have to inject a IKernel(or better IResolutionRoot) into your controller (or better a result factory that is inected to the controller) and let the kernel create the desired action result.

Or do you mean IResultFilter? They are injected too.

I want to be able to inject some custom ActionResults for my application. The current problem I'm dealing with is detailed here:

http://stackoverflow.com/questions/4083352/how-do-i-use-ninject-with-actionresults-while-making-the-controller-ioc-framework

I did find this post that illustrates how to do it:

http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/12/12/enabling-ioc-in-asp-net-actionresults-or-a-better-actionresult.aspx

But unfortunately, it's written for StructureMap and I don't know enough about Ninject to be able to add it to Ninject.Web.Mvc.

Answered on stackoverflow