Injecting a view by means of Simple Injector - is it possible?

Apr 18, 2013 at 10:57 PM
I am in process of choos the DI framework, but due to specific of the product, I will need DI to MVC4 views as well. Does Simple Injector supports it?

Searching the web I have found some examples for Unity here: , however it stands that this is part of ASP.NET MVC DI support. So would this work with Simple Injector or is there any other way to inject a view?
Apr 18, 2013 at 11:32 PM
There is a Simple Injector NuGet Quick Start package for MVC3 and up so MVC4 is definitely supported. Note however that there is currently no NuGet package for Web API, but there is guidance in the wiki about adding DI support to Web API.

About injecting views. MVC3 asks the DependencyResolver.Current for the view it needs and the NuGet Quick Start package for MVC automatically registers a custom DependencyResolver for Simple Injector. This means that you can have a custom constructor on your view or even use property injection, although that takes a little bit more work.

The real question is however: should you actually inject services into your view? In general, views should not have any services. Doing this means that your views get logic and logic (even cross-cutting concerns) does not belong in views. If you're in doubt about this, asking this question at Stackoverflow would have the greatest results. If you give a clear example of what you want to do in the view, you will probably get some great answers soon. If you like, you can cross-reference that question here. This ensures that I take a look at that question as well.
Marked as answer by dot_NET_Junkie on 11/5/2013 at 7:39 AM
Apr 19, 2013 at 9:07 AM
Have posted a question with some details on StackOverflow: . It would be nice if you also look at it.