-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
enhancementNew feature or requestNew feature or request
Description
A message should be able to be published within a given scope, such that only a subscriber who has access to the messagebroker of that scope will be notified of the published message.
There should be a new instance of the broker for each scope, as opposed to reusing the same global reference.
How does a user get an instance?
An overload of the existing factory method?
const scopedMessageBroker = messagebroker<IContracts>('myScope');
How would the dependency injection work? Is there a feature of Needle that can help us here, such as injecting by token?
constructor(@Inject('myScope') private messagebroker: MessageBroker<IContracts>) {}
The trouble here would be registering the necessary instances against the tokens so that they're there when someone tries to inject it... Might need some input from you @Davidhanson90 on how this could work from the Needle point of view
Example
Note the scopes are the same
const broker1 = messagebroker<IContracts>('scope-1');
const broker2 = messagebroker<IContracts>('scope-1'); // should return the same instance
broker1.get('some-channel').subscribe(_msg => console.log('Loud and clear!'));
broker2.create('some-channel').publish('Is anyone receiving?');
// 'Loud and clear!' is logged to the console
now we use separate scopes
const broker1 = messagebroker<IContracts>('scope-1');
const broker2 = messagebroker<IContracts>('scope-2'); // returns a different instance
broker1.get('some-channel').subscribe(_msg => console.log('Loud and clear!'));
broker2.create('some-channel').publish('Is anyone receiving?');
// nothing is logged to the console
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request