简体   繁体   English

MVVM和业务层架构

[英]MVVM and business layer architecture

I am developing an application which I have just finished doing : 我正在开发一个刚完成的应用程序:

  • Domain layer - made in Domain Driven Design way, so I have some logic here 领域层-以领域驱动设计的方式制作,所以这里有一些逻辑
  • Data access layer - with nhibernate and UnitOfWork - Repository pattern 数据访问层-具有nhibernate和UnitOfWork-存储库模式
  • UI layer - MVVM with Caliburn.Micro UI层-带有Caliburn.Micro的MVVM

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.

相关问题 具有业务层和DAL的WPF体系结构 - WPF Architecture with Business Layer and DAL mvvm confustion与模型和业务层连接 - mvvm confustion with the model and business layer connection Web API业务层架构及其职责 - Web API Business Layer Architecture and its responsibilities Web API /业务逻辑层体系结构 - Web API / Business Logic Layer Architecture 具有服务层,业务层和实体框架的N层体系结构 - N-Tier Architecture with Service Layer, Business Layer, and Entity Framework 3层架构 - 在业务层中放置SQL查询是否可行 - 3 Layer Architecture - Is it fine to put sql queries in Business layer N层架构中的服务层和业务层之间有什么区别 - What is difference between a service Layer and Business Layer in N layered architecture 如何检查洋葱架构域层中的业务逻辑? - How to check Business logic in Onion Architecture Domain Layer? REST体系结构:数据访问层作为模型,REST的目的是调用调用DAL的业务逻辑层 - Rest Architecture: Data Access Layer as Model, REST purpose is to call Business Logic Layer that calls DAL 使用自上而下的体系结构,我的业务层无法访问我的数据访问层,这是怎么回事? - With top down architecture my business layer can't access my data access layer, what's wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM