In MVC 3, I understand you can create custom WebViewPages. Can you inject dependencies, using constructor injection, via an IOC container?
In MVC 3, I understand you can create custom WebViewPages. Can you inject dependencies,
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is an expample for view injection in a blog post by Brad Wilson http://bradwilson.typepad.com/blog/2010/07/service-location-pt3-views.html
The statements of the others that views allow constructor injection not entirely correct. Yes
IDependencyResolverenables creating views that have constructor arguments. But unless you are implementing your own view engine this won’t help you at all. Existing view engines like razor will require that you have a parameterless constructor. This means you can do only property injection on views with them.But as the others said you shouldn’t do view injection anyway. Your view should be dumb and just render the view model to HTML. Anything requiring a dependency should be done in the controller or a service.