Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jdgabriel/ddd-domain-events
DDD - Domain Events learning
https://github.com/jdgabriel/ddd-domain-events
ddd ddd-patterns domainevents nodejs typescript
Last synced: 10 days ago
JSON representation
DDD - Domain Events learning
- Host: GitHub
- URL: https://github.com/jdgabriel/ddd-domain-events
- Owner: jdgabriel
- Created: 2023-11-07T17:54:05.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-07T19:55:49.000Z (about 1 year ago)
- Last Synced: 2024-04-28T06:03:53.942Z (7 months ago)
- Topics: ddd, ddd-patterns, domainevents, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### DDD - Domain Events
#### Fluxograma
```mermaid
flowchart TD
A[Order] --> B(new Order)
B --> |event| C(OrderCreatedEvent)
B --> |event| D(OrderPaidEvent)
B --> |persist|G
C --> E
D --> E
F[Database]
E(DomainEvents)
G(Repository)
E --> |persist events|G
G --> |Dispatch events| E
G --> F
```1. Criar uma `Order`;
2. Criar um evento respectivo a sua ação;
3. Salvar em banco de dados (Repositórios);
4. Disparar `DomainEvents` com o `id` da entidade;#### Fluxograma em código
```ts
// src/infra/index.ts// Subscriber
DomainEvents.registerSubscriber(OrderCreatedEvent.name, (order) => {
console.log("order event", order);
});// Subscriber
DomainEvents.registerSubscriber(OrderPaidEvent.name, (order) => {
console.log("paid event", order);
});// Publisher
const order = Order.create({
customerId: "customer_id",
productId: "product_id",
amountInCents: 1000,
status: "pending",
createdAt: new Date(),
});order.pay();
// Dentro da camada de persistência (repositório)
// Finalização do processo de venda
DomainEvents.dispatchEventsForEntity(order.id);
```