ASP.NET Boilerplate

本文探讨了领域驱动设计的核心层——领域层及其在应用层的整合方式,详细阐述了领域实体、业务规则、数据库操作等关键概念。同时强调了DTO验证在应用层的重要性,并介绍了在实际开发中如何通过单元操作确保数据的一致性和准确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I want it to be a start point for all we .NET developers, so, it will be good to develop it together.

特点:继承、自动、约定、扩展

领域层:领域实体、业务规则、操作数据库、

应用层:单元操作、数据传输对象、输入输出对象、应用服务(接口与实现)

Domain layer

In the Domain Driven Design (DDD), the core layer is the Domain Layer. Domain Layer defines your Entities, implements your business rules and so on.

 

Application layer

Application layer does not include domain information and business rules in an ideal application (this may not be possible in the real life but we should minimize it). It mediates between presentation layer and domain layer.

 

Notice that I did not call _taskRepository.Update or any other method to save changes to database. Because, an application service method is a unit of work as default in ASP.NET Boilerplate. For a unit of work method, it basically opens a database connection and begins transaction at the beginning of the method and saves all changes (commits the transaction) to database at the end of the method automatically. It rollbacks the transaction if an Exception is thrown in the execution of the method.

application layer depends only domain (core) layer of the application

 

DTO Validation:

Validating the user input is an application-layer task.

An application service method should validate inputs and throw exceptions if given input is not valid.

But an Application service is a plain class, not derived from Controller. Fortunately, ABP provides similar mechanism for ordinary application service methods (using Castle Dynamic proxies and interception).

One more thing: ABP checks if input parameter of a service method is null. So, you don't need to write guard clauses for that.

I advice to create seperated input and output classes for each application service method even it has only one input argument. This is good when extending the application by adding other arguments to this method. It provides a way of adding parameters to the application service method without breaking existing clients.

开始吧!

转载于:https://www.cnblogs.com/heifengwll/p/5034819.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值