Ninject MVC 3 - Injecting dependencies into models and controllers?

You shouldn't inject anything into the view model. The view model should be a simple data container which is filled from the controller and therefore shouldn't have any dependencies.

Thank you for your reply. I'm not entirely sure whether this is right or wrong. I have slightly more complex mapping which I'm not going to handle with Automapper.

Mapping requires some serialization/deserialization to/from the view/domain models. Currently this logic resides in a controller and it's a mess - there is too much code. – CodeRush Oct 10 at 14:35 My main problem at the moment is that I can't inject anything into my view model.

Once I can inject a service, I'll refactor a code and see whether this is an improvement of what I currently have. Even if it's wrong, I need to see it for myself and understand how I can improve this. – CodeRush Oct 10 at 14:37 Instead of moving code from the controller to the view model you should move the code to services injected to the controller in this case.

– Remo Gloor Oct 10 at 14:39 This means that a service will be dependant on a view model, doesn't it? – CodeRush Oct 10 at 14:41 No. In the end noramlly it is the controller which assigns the values to the model.

The services are there to keep the controller simple and help it to get, convert or calculate the required data. Of course you can pass the model to a service using a method if there is a good reason for it and have it assign some or several values. E.g.

Auto mapping. – Remo Gloor Oct 10 at 15:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions