Utilities types for Domain-Driven Design in TypeScript
Warning
Work in progress.
npm install @jbpionnier/ddd
- ICommandBus / Command / CommandHandler
- IQueryBus / Query / QueryHandler
- IEventBus / Event / EventHandler
- AggregateRoot
- DomainEvent / DomainEventStream
- Entity / ValueObject
- Repository
- EventStream / Saga
- EventStore
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'))