How to pass complex ViewModel to Service Layer in ASP.NET MVC?

You never pass a view model to a service. A service doesn't even know about the existence of a view model that you might have defined in your GUI (ASP. NET MVC) tier.

A service works with domain models. Personally I use AutoMapper to map between view models and models and vice versa, so this logic goes into the mapping layer.

– LukLed Feb 19 at 20:36 @LukLed, the service layer exposes business operations that you could do with the model. Those business operations could be reused among many different applications: ASP. NET MVC, WinForms, WPF, exposed as WCF services, ... View models are just temporary objects to answer a specific needs of a given view.

They are just a representation of the real model. View models are not something that a service layer should bother with. They are too specific to the given application.

– Darin Dimitrov Feb 19 at 20:38 @Darin Dimitrov: My question is, what does it do here? Can you give an example of communication between controller and service in this specific situation, when we are creating user? – LukLed Feb 19 at 20:41 @LukLed, here's an example: a controller action receives a view model from a view, it uses a mapping layer (AutoMapper in my case) to map this view model to a model and then invokes a service method passing it this model.

So the important thing to note here is that the controller communicates with the view only through view models: it receives view models to the view and it passes view models to the view. That's how I do it. – Darin Dimitrov Feb 19 at 20:42 2 @eldar, I think both approaches good.

And by the way for me EF models should not be considered as models (unless you use Code First approach) => those are just autogenerated by assistant database transport objects that should go into a CRUD repository and not a service because they are often polluted/related with the specific data access technology you are using (EF in this case). – Darin Dimitrov Feb 19 at 20:51.

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


Thank You!
send