I have an ASP.NET MVC 3 application.
I have a Model, ViewModel, View, Controller.
I use Ninjectas an IoC.
My Controlleruses ViewModelto transmit data View.
I started using Service(and specific types of interface) to receive information from ViewModeland ask for it against the database to manipulate.
Can I use the same Serviceto adjust ViewModel? Or is contrary to the texture of the design template?
those. Can I edit the settings ViewModelon the level Service?
Scenario
Scenario; My Modelthere are many references to the other Models, so when I set up ViewModelthe controller, it must be detailed, and I feel like Controllerdoing too much. So I want to be able to do something like:
var vm = _serviceProvider.SetupViewModel(Guid model1Id, Guid model2Id, /*etc..*/)
And function SetupViewModelin ServiceProviderwill look like this:
public MyModelViewModel SetupViewModel(Guid model1Id, Guid model2Id, )
{
var vm = new MyModelViewModel();
var model1 = _repository.Model1s.FirstOrDefault(x => x.Id.Equals(model1Id));
var model2 = _repository.Model2s.FirstOrDefault(x => x.Id.Equals(model2Id));
vm.Model1 = model1;
vm.Model2 = model2;
return vm;
}
Having done that, I can also add some conditions null, without having to worry about what my Controllerreally really great!
I use one ViewModelfor action Create / Edit. I do not use ViewModelelsewhere.