From 898c0aea40339597c02bc0f2a6a602d5f1810b46 Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 12 Apr 2020 17:58:24 +0200 Subject: [PATCH 1/3] Implementing DomainEventJsonDeserializer and DomainEventMapping Description: - DomainEventJsonDeserializer. Is in charge of converting a string event to a DomainEvent. - DomainEventMapping It is a collaborator of DomainEventJsonDeserializer. It has the information about the relation between event types and DomainEvents in a map. This map has been constructed dinamically (using the DI) calling the subscribedTo method for the subscribers. So, it treats subscribers as the source of truth. ________________________________________________________________________ There are more work to do in the next commits: - Rethink the types, a huge amount of types with any right now - DomainEvent is receiving the name as param in the constructor but probably it won't be needed. That would allow to only declare an abstract method that will be implemented in each DomainEvent. --- .../domain/CourseCreatedDomainEvent.ts | 6 ++--- .../IncrementCoursesCounterOnCourseCreated.ts | 6 ++--- .../Shared/domain/DomainEventSubscriber.ts | 2 +- .../EventBus/DomainEventJsonDeserializer.ts | 27 +++++++++++++++++++ .../EventBus/DomainEventMapping.ts | 21 +++++++++++++++ .../EventBus/EventEmitterBus.ts | 4 +-- .../EventBus/InMemorySyncEventBus.ts | 4 +-- .../Shared/application.yaml | 9 ++++++- .../InMemoryAsyncEventBus.test.ts | 8 +++--- .../step_definitions/evenBus.steps.ts | 16 ++++------- 10 files changed, 76 insertions(+), 27 deletions(-) create mode 100644 src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts create mode 100644 src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts diff --git a/src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts b/src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts index 1d07f55..2745366 100644 --- a/src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts +++ b/src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent.ts @@ -13,9 +13,9 @@ export class CourseCreatedDomainEvent extends DomainEvent { constructor({ id, - eventId, - duration, name, + duration, + eventId, occurredOn }: { id: string; @@ -42,7 +42,7 @@ export class CourseCreatedDomainEvent extends DomainEvent { body: CreateCourseDomainEventBody, eventId: string, occurredOn: Date - ): CourseCreatedDomainEvent { + ): DomainEvent { return new CourseCreatedDomainEvent({ id: aggregateId, duration: body.duration, diff --git a/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts b/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts index 88aa04f..a59b695 100644 --- a/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts +++ b/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts @@ -1,13 +1,13 @@ import { DomainEventSubscriber } from '../../../../Shared/domain/DomainEventSubscriber'; import { CourseCreatedDomainEvent } from '../../../Courses/domain/CourseCreatedDomainEvent'; -import { CoursesCounterIncrementer } from './CoursesCounterIncrementer'; import { CourseId } from '../../../Shared/domain/Courses/CourseId'; +import { CoursesCounterIncrementer } from './CoursesCounterIncrementer'; export class IncrementCoursesCounterOnCourseCreated implements DomainEventSubscriber { constructor(private incrementer: CoursesCounterIncrementer) {} - subscribedTo(): string[] { - return [CourseCreatedDomainEvent.EVENT_NAME]; + subscribedTo(): any[] { + return [CourseCreatedDomainEvent]; } async on(domainEvent: CourseCreatedDomainEvent) { diff --git a/src/Contexts/Shared/domain/DomainEventSubscriber.ts b/src/Contexts/Shared/domain/DomainEventSubscriber.ts index d1eea04..e17a230 100644 --- a/src/Contexts/Shared/domain/DomainEventSubscriber.ts +++ b/src/Contexts/Shared/domain/DomainEventSubscriber.ts @@ -1,7 +1,7 @@ import { DomainEvent } from './DomainEvent'; export interface DomainEventSubscriber { - subscribedTo(): Array; + subscribedTo(): Array; on(domainEvent: T): Promise; } diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts new file mode 100644 index 0000000..66cce83 --- /dev/null +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts @@ -0,0 +1,27 @@ +import { DomainEvent } from '../../domain/DomainEvent'; +import { DomainEventMapping } from './DomainEventMapping'; + +export class DomainEventJsonDeserializer { + private mapping: DomainEventMapping; + + constructor(mapping: DomainEventMapping) { + this.mapping = mapping; + } + + deserialize(event: string): DomainEvent { + const eventData = JSON.parse(event).data; + const eventName = eventData.type; + const eventClass = this.mapping.for(eventName); + + if (!eventClass) { + throw new Error(`The event ${eventName} doesn't exist or has no subscribers`); + } + + return eventClass.fromPrimitives( + eventData.attributes.id, + eventData.attributes, + eventData.id, + eventData.occurred_on + ); + } +} diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts new file mode 100644 index 0000000..3bb2e35 --- /dev/null +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts @@ -0,0 +1,21 @@ +import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber'; + +export class DomainEventMapping { + mapping: any; + + constructor(mapping: any) { + this.mapping = mapping.reduce((prev: any, subscriber: DomainEventSubscriber) => { + subscriber.subscribedTo().forEach(event => { + prev[event.EVENT_NAME] = event; + }); + return prev; + }, {}); + } + + for(name: string) { + if (!this.mapping[name]) { + throw new Error(`The Domain Event Class for ${name} doesn't exists or have no subscribers`); + } + return this.mapping[name]; + } +} diff --git a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts index 73dc763..4cf309f 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts @@ -1,6 +1,6 @@ +import { EventEmitter } from 'events'; import { DomainEvent } from '../../domain/DomainEvent'; import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber'; -import { EventEmitter } from 'events'; export class EventEmitterBus extends EventEmitter { constructor(subscribers: Array>) { @@ -17,7 +17,7 @@ export class EventEmitterBus extends EventEmitter { private registerSubscriber(subscriber: DomainEventSubscriber) { subscriber.subscribedTo().map(event => { - this.on(event, subscriber.on); + this.on(event.EVENT_NAME, subscriber.on); }); } diff --git a/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts b/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts index b31c481..0d4532c 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts @@ -1,6 +1,6 @@ -import { EventBus } from '../../domain/EventBus'; import { DomainEvent } from '../../domain/DomainEvent'; import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber'; +import { EventBus } from '../../domain/EventBus'; type Subscription = { boundedCallback: Function; @@ -27,7 +27,7 @@ export class InMemorySyncEventBus implements EventBus { } addSubscribers(subscribers: Array>) { - subscribers.map(subscriber => subscriber.subscribedTo().map(event => this.subscribe(event, subscriber))); + subscribers.map(subscriber => subscriber.subscribedTo().map(event => this.subscribe(event.EVENT_NAME, subscriber))); } private subscribe(topic: string, subscriber: DomainEventSubscriber): void { diff --git a/src/apps/mooc_backend/config/dependency-injection/Shared/application.yaml b/src/apps/mooc_backend/config/dependency-injection/Shared/application.yaml index 718a0d9..62137a3 100644 --- a/src/apps/mooc_backend/config/dependency-injection/Shared/application.yaml +++ b/src/apps/mooc_backend/config/dependency-injection/Shared/application.yaml @@ -1,5 +1,4 @@ services: - Mooc.shared.ConnectionManager: factory: class: ../../../../../Contexts/Shared/infrastructure/persistence/mongo/MongoClientFactory @@ -13,3 +12,11 @@ services: Mooc.shared.EventBus: class: ../../../../../Contexts/Shared/infrastructure/EventBus/InMemoryAsyncEventBus arguments: [] + + Mooc.shared.EventBus.DomainEventMapping: + class: ../../../../../Contexts/Shared/infrastructure/EventBus/DomainEventMapping + arguments: ['!tagged domainEventSubscriber'] + + Mooc.shared.EventBus.DomainEventJsonDeserializer: + class: ../../../../../Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer + arguments: ['@Mooc.shared.EventBus.DomainEventMapping'] diff --git a/tests/Contexts/Shared/infrastructure/InMemoryAsyncEventBus.test.ts b/tests/Contexts/Shared/infrastructure/InMemoryAsyncEventBus.test.ts index db84c02..f753b56 100644 --- a/tests/Contexts/Shared/infrastructure/InMemoryAsyncEventBus.test.ts +++ b/tests/Contexts/Shared/infrastructure/InMemoryAsyncEventBus.test.ts @@ -1,7 +1,7 @@ -import { InMemoryAsyncEventBus } from '../../../../src/Contexts/Shared/infrastructure/EventBus/InMemoryAsyncEventBus'; -import { DomainEventSubscriber } from '../../../../src/Contexts/Shared/domain/DomainEventSubscriber'; import { DomainEvent } from '../../../../src/Contexts/Shared/domain/DomainEvent'; +import { DomainEventSubscriber } from '../../../../src/Contexts/Shared/domain/DomainEventSubscriber'; import { Uuid } from '../../../../src/Contexts/Shared/domain/value-object/Uuid'; +import { InMemoryAsyncEventBus } from '../../../../src/Contexts/Shared/infrastructure/EventBus/InMemoryAsyncEventBus'; describe('InMemoryAsyncEventBus', () => { let subscriber: DomainEventSubscriberDummy; @@ -35,8 +35,8 @@ class DummyEvent extends DomainEvent { } class DomainEventSubscriberDummy implements DomainEventSubscriber { - subscribedTo(): string[] { - return [DummyEvent.EVENT_NAME]; + subscribedTo(): any[] { + return [DummyEvent]; } async on(domainEvent: DummyEvent) { diff --git a/tests/apps/mooc_backend/features/step_definitions/evenBus.steps.ts b/tests/apps/mooc_backend/features/step_definitions/evenBus.steps.ts index b8e4631..751ff59 100644 --- a/tests/apps/mooc_backend/features/step_definitions/evenBus.steps.ts +++ b/tests/apps/mooc_backend/features/step_definitions/evenBus.steps.ts @@ -1,19 +1,13 @@ import { Given } from 'cucumber'; import container from '../../../../../src/apps/mooc_backend/config/dependency-injection'; import { EventBus } from '../../../../../src/Contexts/Shared/domain/EventBus'; -import { CourseCreatedDomainEvent } from '../../../../../src/Contexts/Mooc/Courses/domain/CourseCreatedDomainEvent'; +import { DomainEventJsonDeserializer } from '../../../../../src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer'; -Given('I send an event to the event bus:', async (event: any) => { - const eventBus = container.get('Mooc.shared.EventBus') as EventBus; - const jsonEvent = JSON.parse(event).data; +const eventBus = container.get('Mooc.shared.EventBus') as EventBus; +const deserializer = container.get('Mooc.shared.EventBus.DomainEventJsonDeserializer') as DomainEventJsonDeserializer; - const domainEvent = CourseCreatedDomainEvent.fromPrimitives( - jsonEvent.attributes.id, - jsonEvent.attributes, - jsonEvent.id, - jsonEvent.occurred_on - ); +Given('I send an event to the event bus:', async (event: any) => { + const domainEvent = deserializer.deserialize(event); await eventBus.publish([domainEvent]); }); - From 6b9637985a3c4e4cb4e86a714baa63050f9ca762 Mon Sep 17 00:00:00 2001 From: David Matas Date: Sun, 12 Apr 2020 21:16:11 +0200 Subject: [PATCH 2/3] A bit of refactor and better types Created the DomainEventClass to reflect that each DomainEvent constructor has that type. To do that DomainEvent has been extended with the static properties that will be accesed in each DomainEvent class. --- .../IncrementCoursesCounterOnCourseCreated.ts | 3 +- src/Contexts/Shared/domain/DomainEvent.ts | 4 ++ .../Shared/domain/DomainEventSubscriber.ts | 4 +- .../EventBus/DomainEventJsonDeserializer.ts | 2 +- .../EventBus/DomainEventMapping.ts | 39 +++++++++++++------ .../EventBus/EventEmitterBus.ts | 2 +- .../EventBus/InMemorySyncEventBus.ts | 4 +- 7 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts b/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts index a59b695..eb4271b 100644 --- a/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts +++ b/src/Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated.ts @@ -1,3 +1,4 @@ +import { DomainEventClass } from '../../../../Shared/domain/DomainEvent'; import { DomainEventSubscriber } from '../../../../Shared/domain/DomainEventSubscriber'; import { CourseCreatedDomainEvent } from '../../../Courses/domain/CourseCreatedDomainEvent'; import { CourseId } from '../../../Shared/domain/Courses/CourseId'; @@ -6,7 +7,7 @@ import { CoursesCounterIncrementer } from './CoursesCounterIncrementer'; export class IncrementCoursesCounterOnCourseCreated implements DomainEventSubscriber { constructor(private incrementer: CoursesCounterIncrementer) {} - subscribedTo(): any[] { + subscribedTo(): DomainEventClass[] { return [CourseCreatedDomainEvent]; } diff --git a/src/Contexts/Shared/domain/DomainEvent.ts b/src/Contexts/Shared/domain/DomainEvent.ts index 42aa327..05133d2 100644 --- a/src/Contexts/Shared/domain/DomainEvent.ts +++ b/src/Contexts/Shared/domain/DomainEvent.ts @@ -1,6 +1,8 @@ import { Uuid } from './value-object/Uuid'; export abstract class DomainEvent { + static EVENT_NAME: string; + static fromPrimitives: (...args: any[]) => any; readonly aggregateId: string; readonly eventId: string; readonly occurredOn: Date; @@ -15,3 +17,5 @@ export abstract class DomainEvent { abstract toPrimitive(): Object; } + +export type DomainEventClass = Partial; diff --git a/src/Contexts/Shared/domain/DomainEventSubscriber.ts b/src/Contexts/Shared/domain/DomainEventSubscriber.ts index e17a230..931771e 100644 --- a/src/Contexts/Shared/domain/DomainEventSubscriber.ts +++ b/src/Contexts/Shared/domain/DomainEventSubscriber.ts @@ -1,7 +1,7 @@ -import { DomainEvent } from './DomainEvent'; +import { DomainEvent, DomainEventClass } from './DomainEvent'; export interface DomainEventSubscriber { - subscribedTo(): Array; + subscribedTo(): Array; on(domainEvent: T): Promise; } diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts index 66cce83..01efda9 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts @@ -17,7 +17,7 @@ export class DomainEventJsonDeserializer { throw new Error(`The event ${eventName} doesn't exist or has no subscribers`); } - return eventClass.fromPrimitives( + return eventClass.fromPrimitives!( eventData.attributes.id, eventData.attributes, eventData.id, diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts index 3bb2e35..9796a21 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts @@ -1,21 +1,36 @@ +import { DomainEventClass } from '../../domain/DomainEvent'; import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber'; +type Mapping = Map; + export class DomainEventMapping { - mapping: any; - - constructor(mapping: any) { - this.mapping = mapping.reduce((prev: any, subscriber: DomainEventSubscriber) => { - subscriber.subscribedTo().forEach(event => { - prev[event.EVENT_NAME] = event; - }); - return prev; - }, {}); + mapping: Mapping; + + constructor(mapping: DomainEventSubscriber[]) { + this.mapping = mapping.reduce(this.eventsExtractor(), new Map()); + } + + private eventsExtractor() { + return (map: Mapping, subscriber: DomainEventSubscriber) => { + subscriber.subscribedTo().forEach(this.eventNameExtractor(map)); + return map; + }; } - for(name: string) { - if (!this.mapping[name]) { + private eventNameExtractor(map: Mapping): (domainEvent: DomainEventClass) => void { + return domainEvent => { + const eventName = domainEvent.EVENT_NAME!; + map.set(eventName, domainEvent); + }; + } + + for(name: string): DomainEventClass { + const domainEvent = this.mapping.get(name); + + if (!domainEvent) { throw new Error(`The Domain Event Class for ${name} doesn't exists or have no subscribers`); } - return this.mapping[name]; + + return domainEvent; } } diff --git a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts index 4cf309f..223ce7c 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts @@ -17,7 +17,7 @@ export class EventEmitterBus extends EventEmitter { private registerSubscriber(subscriber: DomainEventSubscriber) { subscriber.subscribedTo().map(event => { - this.on(event.EVENT_NAME, subscriber.on); + this.on(event.EVENT_NAME!, subscriber.on); }); } diff --git a/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts b/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts index 0d4532c..4d30d1d 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/InMemorySyncEventBus.ts @@ -27,7 +27,9 @@ export class InMemorySyncEventBus implements EventBus { } addSubscribers(subscribers: Array>) { - subscribers.map(subscriber => subscriber.subscribedTo().map(event => this.subscribe(event.EVENT_NAME, subscriber))); + subscribers.map(subscriber => + subscriber.subscribedTo().map(event => this.subscribe(event.EVENT_NAME!, subscriber)) + ); } private subscribe(topic: string, subscriber: DomainEventSubscriber): void { From aa9feb7e4242cd436861b802677aaee3fd63b2fd Mon Sep 17 00:00:00 2001 From: Fernando Vilas Maciel Date: Sun, 26 Apr 2020 17:07:06 +0200 Subject: [PATCH 3/3] Remove optionals from DomainEventClass --- src/Contexts/Shared/domain/DomainEvent.ts | 2 +- .../EventBus/DomainEventJsonDeserializer.ts | 2 +- .../Shared/infrastructure/EventBus/DomainEventMapping.ts | 8 ++++---- .../Shared/infrastructure/EventBus/EventEmitterBus.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Contexts/Shared/domain/DomainEvent.ts b/src/Contexts/Shared/domain/DomainEvent.ts index 05133d2..93729ae 100644 --- a/src/Contexts/Shared/domain/DomainEvent.ts +++ b/src/Contexts/Shared/domain/DomainEvent.ts @@ -18,4 +18,4 @@ export abstract class DomainEvent { abstract toPrimitive(): Object; } -export type DomainEventClass = Partial; +export type DomainEventClass = { EVENT_NAME: string, fromPrimitives(...args: any[]): DomainEvent; }; diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts index 01efda9..66cce83 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventJsonDeserializer.ts @@ -17,7 +17,7 @@ export class DomainEventJsonDeserializer { throw new Error(`The event ${eventName} doesn't exist or has no subscribers`); } - return eventClass.fromPrimitives!( + return eventClass.fromPrimitives( eventData.attributes.id, eventData.attributes, eventData.id, diff --git a/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts index 9796a21..cdcd229 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/DomainEventMapping.ts @@ -1,4 +1,4 @@ -import { DomainEventClass } from '../../domain/DomainEvent'; +import { DomainEventClass, DomainEvent } from '../../domain/DomainEvent'; import { DomainEventSubscriber } from '../../domain/DomainEventSubscriber'; type Mapping = Map; @@ -6,12 +6,12 @@ type Mapping = Map; export class DomainEventMapping { mapping: Mapping; - constructor(mapping: DomainEventSubscriber[]) { + constructor(mapping: DomainEventSubscriber[]) { this.mapping = mapping.reduce(this.eventsExtractor(), new Map()); } private eventsExtractor() { - return (map: Mapping, subscriber: DomainEventSubscriber) => { + return (map: Mapping, subscriber: DomainEventSubscriber) => { subscriber.subscribedTo().forEach(this.eventNameExtractor(map)); return map; }; @@ -19,7 +19,7 @@ export class DomainEventMapping { private eventNameExtractor(map: Mapping): (domainEvent: DomainEventClass) => void { return domainEvent => { - const eventName = domainEvent.EVENT_NAME!; + const eventName = domainEvent.EVENT_NAME; map.set(eventName, domainEvent); }; } diff --git a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts index 223ce7c..4cf309f 100644 --- a/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts +++ b/src/Contexts/Shared/infrastructure/EventBus/EventEmitterBus.ts @@ -17,7 +17,7 @@ export class EventEmitterBus extends EventEmitter { private registerSubscriber(subscriber: DomainEventSubscriber) { subscriber.subscribedTo().map(event => { - this.on(event.EVENT_NAME!, subscriber.on); + this.on(event.EVENT_NAME, subscriber.on); }); }