Skip to content

notification handler

Massimo Giambona edited this page Mar 1, 2021 · 2 revisions

How to use the Notification

const result: string[] = [];

// The notification class
class Ping implements INotification {
    constructor(public value?: string){}
}

// The notification handler
// You can opionally specify an order in which the message must be processed.
@NotificationHandler(Ping, 1)
class Pong1 implements INotificationHandler<Ping> {
    async handle(notification: Ping): Promise<void> {
        result.push(notification.value);
    }
}

const mediator = new Mediator();
mediator.publish(new Ping(message));

// result: [ "Foo" ]

Notes

If you want Inversify to resolve the NotificationHandler you should configure the resolver property of mediatorSettings see the configure