Intermediate ASP.NET Core Tutorial - Online Shop Ep.6 - View Models

preview_player
Показать описание
In this episode I show and talk about how to and benefits of keeping your View Models inside your application level and not in your UI layer.

This is more of a break from the last couple of long episodes, so brace your self for some long episodes!

Рекомендации по теме
Комментарии
Автор

Most of all, thanks for this excellent series.

I am used to MVVM pattern of Xamarin.Forms.
It seems Ep.5 and Ep.6 shows how to split the concerns of Model, View, and ViewModel by project.

However, the terms of ViewModel in your project looks a little bit different from that of Xamarin MVVM, where VM is handling logics by using models. I think, in your project, each component of Xamarin V-VM-M can be represented by Shop.UI - Shop.Application - Shop.Domain respectively. Shop.Database is providing workers for Shop.Application objects(ViewModel).



My idea is Product property of Index page is just a part of View, not ViewModel. The property just serves as a data basket, to which the model binding of Asp.Net Core hand over data from http request.

The type name of Product property ends with ViewModel and it is very confusing to me.

Normally, ViewModel objects should open methods to View so that View can call on demand. More importantly, parameters of those methods should be in basic types.

A DTO-like objects can be defined to share data between View and ViewModel but i think it is not recommended because ViewModel is a direct child of View so DTO is an unnecessary encapsulation step.

In your project, ProductViewModel is the case. It doesn't only result in more complexity in the name space hierarchy but also produces an extra class that View developers should know to make their View working correctly, while the only thing View maker should know is ViewModel class.

I am not a professional developer and this is not criticizing you. I just look forward to your comments on my idea.

okcharles
Автор

So, basically This is Model-view-viewmodel way of coding and

Shop.Domain is the Model,
Shop.Application is ViewModel,
whereas Shop.UI is the view part right?

Brombrom