[英]MVVM and business layer architecture
I am developing an application which I have just finished doing : 我正在开发一个刚完成的应用程序:
Now the question is : where I put my logic? 现在的问题是:我把逻辑放在哪里?
According to 根据
https://softwareengineering.stackexchange.com/questions/185448/mvvm-clarification https://softwareengineering.stackexchange.com/questions/185448/mvvm-clarification
I have to split the application logic from the domain logic but I do a simple example : 我必须将应用程序逻辑与域逻辑分开,但我做了一个简单的示例:
I have a ViewModel that only to charge a person from the db and allow the changes, then I will have 3 methods (to keep simply the example): 我有一个ViewModel,只能从数据库中收取费用并允许更改,然后我将有3种方法(仅保留示例):
LoadPerson ( id )
SavePerson (Person )
CanEditPerson ( id )
The first 2 must call the corresponding methods of my UoW
but must do so directly ? 前2个必须调用我的
UoW
的相应方法,但必须直接调用吗?
In an earlier application made with asp.net I created a businessLayer with a facade for each page, so the page calls the LoadPerson
of the facade and then BL call the LoadPerson
of the data access layer. 在一个用asp.net制作的较早的应用程序中,我为每个页面创建了一个带有外观的businessLayer,因此该页面调用外观的
LoadPerson
,然后BL调用数据访问层的LoadPerson
。
It's a correct way that I could use here? 这是我可以使用的正确方法吗?
But in that case, the pages were very complex and worked on a variety of objects: I had 6 page (full of tab and accordion) for an application that was based on about 100 items. 但是在那种情况下,页面非常复杂并且可以处理多种对象:对于基于大约100个项目的应用程序,我只有6页(充满制表符和手风琴)。
Here I understand that the view must be very simple and possibly work on a single object, I should then have a facade in the BL for each ViewModel
? 在这里,我知道视图必须非常简单,并且可以在单个对象上工作,然后对于每个
ViewModel
,我应该在BL中有一个外观。
CanEditPerson
must be a method that verifies the rules established to determine whether the current user can change the person or not. CanEditPerson
必须是一种验证建立的规则的方法,以确定当前用户是否可以更改此人。 It seems very logical domain (the buyers have to establish pemessi) own the copyright but I do not know how to handle this thing in DomainLayer
, I would be much more natural to have the method in a BusinessLayer
似乎非常合乎逻辑的领域(购买者必须建立pemessi)拥有版权,但是我不知道如何在
DomainLayer
处理此事情,在BusinessLayer
使用该方法会更自然
You can also Create a one Model Here and declare Property and Method in it. 您也可以在此处创建一个模型,并在其中声明属性和方法。 like
喜欢
public class Person
{
//Declare your property
LoadPerson ( id )
{
}
SavePerson (Person )
{
}
CanEditPerson ( id )
{
}
}
Now You have to just create Property of Person class in your ViewModel so you can easily access their property as well as Methods. 现在,您只需要在ViewModel中创建Person类的Property,就可以轻松访问其Property和Methods。
private Person _PersonDetails;
public Person PersonDetails
{
get { return _PersonDetails??(_PersonDetails=new Person());}
set { _PersonDetails = value;}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.