@ddd-框架/核心
@ddd-framework/core是一个在综合@ddd-framework框架。 它为专门为Node.js实施域驱动设计(DDD)提供了基本的功能和类别.
导言
这个 @ddd-framework/core 软件包是 @ddd-framework它提供了一系列特点和工具,对于将DDD原则纳入节点应用至关重要。 这个软件包在精简开发流程,改进代码组织,以及根据DDD原则创建强大而可维护的应用程序等方面发挥了重要作用.
文档
更详细的文件类型 @ddd-framework/core请参考 正式文件。 。 。 .
安装
要安装 @ddd-framework/core,确保您具备下列先决条件:
- 节点.js 稳定版本
- 小时
一旦设置了先决条件,就运行以下命令:
$ pnpm i @ddd-framework/core
...
这将安装 @ddd-framework/core 软件包及其依赖性.
特征
这个 @ddd-framework/core 软件包提供了一套符合域驱动设计(DDD)原理的功能来方便节点.js应用程序的开发:
- 总数和实体: 提供装饰和类,例如:
AggregateRoot财务报告和审定财务报表Entity用于模拟和管理域集合和实体。 这些类囊括了行为,执行业务规则,并使得域模型内部的一致性得以实现. - 域事件: 提供
DomainEvent用于表示和处理域事件的装饰器. 域事件用于捕捉域内有意义的事件并允许应用程序不同部分之间的脱钩通信. - 值对象编号:
ValueObject分类以定义不可变值对象。 价值对象用自己的规则和行为来封装小而有凝聚力的数据片段,有助于域模型的完整性和表达性. - 域基质: 提供域原始类, 如
DateValue包含特定域概念,并确保域模型内的类型安全和一致性. - 仓库: 提供
Repository分类,它起到抽象的作用,以域不可知的方式访问并坚持集合和实体. 仓库能够以一致而标准化的方式取回并存储域对象. - 工作单位: 提供
UnitOfWork财务报告和审定财务报表UnitOfWorkManager执行工作单位模式。 这些类别提供了一种管理交易一致性和协调单一业务内多个总体或实体变化的方法. - 例外处理: 提供一系列例外类别,包括:
ArgumentException, (中文(简体) ),InvalidOperationException,以及更多,处理在域操作中可能出现的特殊情况和出错.
通过利用这些特点,从 @ddd-framework/core 软件包,开发者可以在他们的Node.js应用程序中有效实现DDD概念,如聚合,实体,域事件,和寄存器,从而导致更可维护,更能表达,更注重域的代码.
使用量
用于 @ddd-framework/core,从软件包中导入想要的类、接口或函数。 例如:
import {
AggregateId,
AggregateRoot,
Entity,
EntityId,
IllegalStateException
} from '@ddd-framework/core';
import { faker } from '@faker-js/faker';
@AggregateRoot()
export class GiftCard extends Entity {
@AggregateId()
public id: string;
public remainingValue: number;
public transactions: GiftCardTransaction[] = [];
constructor(id: string, initialBalance: number) {
super();
this.id = id;
this.remainingValue = initialBalance;
}
@Entity.Invariant()
public handle(cmd: TransactCommand | ReimburseCardCommand) {
if (cmd instanceof TransactCommand) {
const transaction = new GiftCardTransaction(
faker.string.uuid(),
cmd.transactionValue
);
this.remainingValue -= transaction.transactionValue;
this.transactions.push(transaction);
this.raise(
new TransactionEvent(
this.id,
transaction.transactionId,
transaction.transactionValue
)
);
} else if (cmd instanceof ReimburseCardCommand) {
const transaction = this.transactions.find(
(i) => i.transactionId === cmd.transactionId
);
if (transaction) {
this.remainingValue += transaction.transactionValue;
transaction.handle(cmd);
}
}
}
protected validateInvariants(): void {
if (this.remainingValue < 0)
throw new IllegalStateException('Gift card cannot be overdrawn');
}
}
许可证
@ddd-framework/core 以麻省理工学院的许可证发放。 随你随意定制吧 更适合你的需要.