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