import { DynamicModule, Global, Module, Type } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; import { AggregateRehydrator } from './aggregate-rehydrator'; import { EventRecorder } from './event-recorder'; /** * Shared building blocks for every bounded context: the event store (from * the infrastructure module plugged in by the composition root), the * AggregateRehydrator and the EventRecorder. */ @Global() @Module({}) export class SharedModule { static withInfrastructure( infrastructureModule: Type | DynamicModule, ): DynamicModule { return { module: SharedModule, imports: [CqrsModule, infrastructureModule], providers: [AggregateRehydrator, EventRecorder], exports: [infrastructureModule, AggregateRehydrator, EventRecorder], }; } }