File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
Contexts/Shared/infrastructure/EventBus
config/dependency-injection Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ export class EventEmitterBus extends EventEmitter {
1717
1818 private registerSubscriber ( subscriber : DomainEventSubscriber < DomainEvent > ) {
1919 subscriber . subscribedTo ( ) . map ( event => {
20- this . on ( event . EVENT_NAME , subscriber . on ) ;
20+ this . on ( event . EVENT_NAME , subscriber . on . bind ( subscriber ) ) ;
2121 } ) ;
2222 }
2323
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import cookieSession from 'cookie-session';
88import cookieParser from 'cookie-parser' ;
99import flash from 'connect-flash' ;
1010import nunjucks from 'nunjucks' ;
11+ import { registerSubscribers } from './subscribers' ;
1112
1213const app : express . Express = express ( ) ;
1314
@@ -43,5 +44,6 @@ app.use(helmet.frameguard({ action: 'deny' }));
4344app . use ( compress ( ) ) ;
4445
4546registerRoutes ( app ) ;
47+ registerSubscribers ( ) ;
4648
4749export default app ;
Original file line number Diff line number Diff line change @@ -46,6 +46,19 @@ services:
4646 tags :
4747 - { name: 'queryHandler' }
4848
49+ Mooc.coursesCounter.CoursesCounterIncrementer :
50+ class : ../../../../../Contexts/Mooc/CoursesCounter/application/Increment/CoursesCounterIncrementer
51+ arguments : [
52+ " @Mooc.coursesCounter.CoursesCounterRepository" ,
53+ " @Mooc.shared.EventBus"
54+ ]
55+
56+ Mooc.coursesCounter.IncrementCoursesCounterOnCourseCreated :
57+ class : ../../../../../Contexts/Mooc/CoursesCounter/application/Increment/IncrementCoursesCounterOnCourseCreated
58+ arguments : ["@Mooc.coursesCounter.CoursesCounterIncrementer"]
59+ tags :
60+ - { name: 'domainEventSubscriber' }
61+
4962 Mooc.courses.CreateCourseCommandHandler :
5063 class : ../../../../../Contexts/Mooc/Courses/application/CreateCourseCommandHandler
5164 arguments : ['@Mooc.courses.CourseCreator']
Original file line number Diff line number Diff line change 1+ import container from './config/dependency-injection' ;
2+ import { InMemoryAsyncEventBus } from '../../../Contexts/Shared/infrastructure/EventBus/InMemoryAsyncEventBus' ;
3+ import { Definition } from 'node-dependency-injection' ;
4+ import { DomainEventSubscriber } from '../../../Contexts/Shared/domain/DomainEventSubscriber' ;
5+ import { DomainEvent } from '../../../Contexts/Shared/domain/DomainEvent' ;
6+
7+ export function registerSubscribers ( ) {
8+ const eventBus = container . get ( 'Mooc.shared.EventBus' ) as InMemoryAsyncEventBus ;
9+ const subscriberDefinitions = container . findTaggedServiceIds ( 'domainEventSubscriber' ) as Map < String , Definition > ;
10+ const subscribers : Array < DomainEventSubscriber < DomainEvent > > = [ ] ;
11+
12+ subscriberDefinitions . forEach ( ( value : any , key : any ) => subscribers . push ( container . get ( key ) ) ) ;
13+ eventBus . addSubscribers ( subscribers ) ;
14+ }
You can’t perform that action at this time.
0 commit comments