Skip to content

jbpionnier/ts-ddd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

828686f · Feb 25, 2024

History

24 Commits
Feb 25, 2024
Feb 25, 2024
Aug 20, 2019
Apr 5, 2021
Aug 20, 2019
Aug 20, 2019
Aug 20, 2019
Aug 20, 2019
Feb 25, 2024
Feb 25, 2024
Feb 25, 2024
Jan 27, 2023

Repository files navigation

ts-ddd

npm version Build Status npm

Utilities types for Domain-Driven Design in TypeScript

Warning

Work in progress.

Installation

npm install @jbpionnier/ddd

Usage

  • ICommandBus / Command / CommandHandler
  • IQueryBus / Query / QueryHandler
  • IEventBus / Event / EventHandler
  • AggregateRoot
  • DomainEvent / DomainEventStream
  • Entity / ValueObject
  • Repository
  • EventStream / Saga
  • EventStore

ICommandBus / Command / CommandHandler

import { ICommandBus, ICommandHandler, Command } from '@jbpionnier/ddd'

class MyCommand implements Command {
  constructor(public readonly id: string) {}
}

@CommandHandler(MyCommand)
class MyCommandHandler implements ICommandHandler<ImportMediaCommand> {
  handle(command: MyCommand): void {
    console.log('Handling command', command)
  }
}
// Create the command bus
const commandBus: ICommandBus = new CommandBus()
commandBus.register(new MyCommandHandler())

// Execute the command
commandBus.execute(new MyCommand('123'))