Reputation: 1393
I am using Prism's Event Aggregator and I publish an event from my composite control. But if a developer uses two instances of the control on the same form, how can a subscriber differentiate the events? What is the best practice?
Thank you.
Upvotes: 0
Views: 93
Reputation: 132548
Typically I just pass the caller or a callerId in the EventMessage
, and the subscriber ignores the message if the caller isn't what it expects
// Subscribe
eventAggregator.GetEvent<SomeEvent>().Subscribe(SomeMethod);
public void ShowNews(SomeEventMessage e)
{
if (e.CallerId != this.Id)
return;
Do Work();
}
// Broadcast
eventAggregator.GetEvent<SomeEvent>().Publish(
new SomeEventMessage { CallerId = this.Id });
Upvotes: 1