In DevDash, I have a minimal event object called ILocalBus. It’s an easy way for unconnected objects to stay in touch. Anything can publish an event, and anything else can consume it. The messages are distributed to the subscribers asynchronously.
Today, someone showed a similar piece of code using object provided by PRISM. So, tonight’s topic was PRISM.
I did a search for Microsoft Prism, and I got a few links that were already visited. I did some reading on Prism earlier, and forgot about it. Why? Well, as soon as you click a link, you learn that it’s for WPF and Silverilght developmernt. Yea… I don’t do WPF or Silverlight development. Anything involving a visual component isn’t in my areas of interest or expertise. But, I read it anyway.
I wasn’t going to read all of this: http://msdn.microsoft.com/en-us/library/gg430865(PandP.40).aspx
But, I jumped to the section that I saw in code:
The section of interest is EVENT AGGREGATION.
Clearly, this thing is for WPF and Silverlight. It says it very frequently, but perhaps this one component is worthwhile outside of the gui. Even the event is called CompositePresentationEvent… not appealing, but it might work.
One interesting parameter is the ThreadOption when subscribing.
- Publisher Thread – The default setting. So, the subscribers will block the publisher.
- UI Thread – n/a for how I would want to use it.
- Background Thread – that’s the ticket.
As I’ve mentioned before, my event bus is ILocalBus, and the implementation of it is StupidBus. I called it that to make sure it’s never accidentally over glorified. Yes, it’s really cool and really simple. It lets objects that know not of each other’s existence communicate with one another. But, in the end, it’s done with simple .net constructs. I see how I would like it to evolve, but chances are there’s already an object out there ready to go. Maybe the Prism EventAggregator is that class.