您将如何在mvvm中设计与Viewmodel的业务逻辑交互 [英] How would you design business logic interaction with Viewmodel in mvvm

查看:204
本文介绍了您将如何在mvvm中设计与Viewmodel的业务逻辑交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


视图模型可以获得业务逻辑的方式有哪些。可以说,我有3个模型,基于这3个模型数据,我将生成(基本上计算)一些新值(比如模型4),我将在View中显示这个模型4数据。



注意我不能将计算逻辑放在服务端,因为我没有控制权。我必须在我身边计算模型4.我应该在哪里计算这个模型4值?



问题1)调用服务表单ViewModel即GetModel_1_Data,GetModel_2_Data,GetModel_3_Data是不是很好的做法?



2)根据mvvm,我不允许在ViewModel上拥有业务逻辑......那我该怎么办?我们有什么不同的方式来实现这个目标?



3)在Mvvm中,我看到UI消耗的模型基本上是使用INotifyProperty的模型..什么是正确的单词来调用它们...我可以称为UI模型吗?或UI模型对象?其他模型就像普通的CLR对象一样。



当我读到关于mvvm的许多人说要保持Model..whic模型中的逻辑..他们的意思是普通的clr类......或者UI模型(他们有INotifyPropertyChanged)如果我们不需要有一些层来从POCO模型生成UI模型吗?这层被称为
..如此......



谢谢你,


解决方案



嗨  nellis2,


UI处理演示责任,业务层处理验证,数据访问层处理SQL。

  3层架构的优点如下: -

•包含的变化: - 一层中的变化不会在其他层中复制。

•可重用性: - 增加了可重用性,因为每个层都是独立的,独立的和个体的实体。


据我所知,MVVM是3层架构的演变。


以下教程和示例供您参考。


Silverlight对MVVM概念的简单介绍:

https://www.codeproject.com/Articles/186705/ A-Totally-Simple-Introduction-to-the-MVVM-Concept


MVVM一步一步(基础知识升级)

https://www.codeproject.com/Articles/819294/ WPF-MVVM - 逐步 - 基础到高级


使用Silverlight的MVVM(从头到尾):

< a href ="https://code.msdn.microsoft.com/silverlight/MVVM-with-Silverlight-09a2493a"> https://code.msdn.microsoft.com/silverlight/MVVM-with-Silverlight-09a2493a




最好的问候,


Yohann Lu



What are the ways where a viewmodel can get business logic. Lets say, I have 3 Models and based those 3 models data I will produce(basically calculation) some new values(lets say model 4) where I will show this Model 4 data in View.

Note I can not put calculation logic on service side because i dont have control..on them. I have to compute Model 4 on my side.. Where should I compute this Model 4 Values?

Questions 1) Is it good practice to call Service form ViewModel i.e GetModel_1_Data,GetModel_2_Data, GetModel_3_Data if not whats the good practice ?

2) As per mvvm I am not allowed to have business logic on ViewModel ...then where should I do? What are different ways we can achieve..this ?

3) In Mvvm I see models consumed by UI basically Models with INotifyPropertychanged .. what is the right word to call them.. can I call as UI Models? or UI model objects? Other Models just like plain CLR objects.

when I read about mvvm many say to keep logic in Model..whic model ..does they mean plain clr classes..or UI models(where they have INotifyPropertyChanged) If not do we need to have some layer to produce UI Models from POCO models? What this layer is called ..if so...

Thankyou,


解决方案


Hi  nellis2,

UI handles the presentation responsibility, business layer handles validations and data access layer handles SQL.
 The advantages of 3 layer architecture are as follows:-
•Contained changes: -Changes in one layer do not replicate across other layers.
•Reusability: -Increased reusability because each layers are separate, self-contained and individual entities.

As far as I know, the MVVM is an evolution of 3 layer architecture.

The following tutorials and example for your reference.

A Totally Simple Introduction to the MVVM Concept with Silverlight:
https://www.codeproject.com/Articles/186705/A-Totally-Simple-Introduction-to-the-MVVM-Concept

MVVM step by step (Basics to Advance Level)
https://www.codeproject.com/Articles/819294/WPF-MVVM-step-by-step-Basics-to-Advance-Level

MVVM with Silverlight (Begin to End):
https://code.msdn.microsoft.com/silverlight/MVVM-with-Silverlight-09a2493a


Best Regards,

Yohann Lu


这篇关于您将如何在mvvm中设计与Viewmodel的业务逻辑交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆