Molecule icon indicating copy to clipboard operation
Molecule copied to clipboard

How to use multiple services and events providers ?

Open labordep opened this issue 4 months ago • 0 comments

Discussed in https://github.com/OpenSmock/Molecule/discussions/162

Originally posted by labordep June 9, 2023 The problem appears when we are using multiple Components with the same contract definition (static), during the execution we are subscribe to multiple components and we are interesseted of uses same services contract from mutiple Component with different name.

For events, actually we are receiving all events but without the way to know the name of the emitter. A solution is to add the name of the emitter directly in the arguments of the events but this is not compatible with Component principles (do not modify used contract). For services, a solution is to create a services method manually which invoke the services from the targeted Component name, but this is uggly.

May be some solutions :

  • Services : Return a proxy when a service is called self myUsedComponentServices componentNamed: #componentB myServices
  • Events : get the name of the provider from the stack, as an example using thisContext to get the name of the emitter

labordep avatar Oct 01 '24 21:10 labordep