@ddd-框架/收集
@ddd-framework/collections是一个在综合@ddd-framework框架。 它提供专门为Node.js设计的域驱动设计(DDD)背景下管理收藏的课目.
说明
这个 @ddd-framework/collections 软件包扩展函数 @ddd-framework 提供与收藏有关的额外课程。 这些公用设施有助于以面向DDD的方式在Node.js应用中管理和管理收集.
文档
详细信息 @ddd-framework/collections请参考 正式文件。 。 。 .
安装
要安装 @ddd-framework/collections,确保您具备下列先决条件:
- 节点.js 稳定版本
- 小时
一旦设置了先决条件,就运行以下命令:
$ pnpm i @ddd-framework/collections
...
这将安装 @ddd-framework/collections 软件包及其依赖性.
特征
这个 @ddd-framework/collections 软件包提供以下特性:
- 实体合并编号:
EntityCollectionclass 代表域模型中实体的集合。 它为管理和访问收藏中的实体提供了方便的方法. - 列表编号:
Listclass 是不可改变的指令集,允许存储和操纵元素。 它提供各种操作,如从列表中添加,去除,取回元素,等等.
通过利用来自 @ddd-framework/collections 软件包,开发者可以按照DDD原则有效管理实体的集合并列出其Node.js应用中的列表.
使用量
用于 @ddd-framework/core,从软件包中导入想要的类、接口或函数。 例如:
import {
Entity,
EntityCollection,
EntityId,
Identity,
IllegalStateException
} from '@ddd-framework/core';
class UserId extends Identity {
protected validate(): void {
if (!this.value) throw new IllegalStateException('id is required');
}
}
class User extends Entity {
@EntityId()
public id: UserId;
constructor(id: UserId) {
super();
this.id = id;
}
}
const user = new User(new UserId(faker.string.uuid()));
const collection = new EntityCollection<User>();
expect(collection.add(user).contains(user)).toBeTruthy();
许可证
@ddd-framework/collections 以麻省理工学院的许可证发放。 随你随意定制吧 更适合你的需要.