Events in CAB (aka Composite UI App Block)

I’m jumping into a CAB project soon so I’m reviewing the architecture to try and spot the hidden pain points. Composite UI Application Block is Microsoft’s pattern’s & practices Inversion Of Control (or Dependency Injection) framework.

I’m starting with EventBroker because its the simplest construct of the App Block.

CAB Events come in 2 parts:

Publishers:

Event Publish Point

And Subscribers:

Event Subscriber Point

And that’s all; there is no point in the code where you have to actually attach the handler. It’s done for you by the framework. Handy, but why bother? The Cabpedia article above highlights a number of advantages but I think they can be boiled down to 3: CAB Events are Global, Weakly Typed and Many-to-Many.

Weak Typing

So we’ve all been taught the value of strong typing. Compile-Time errors about type mismatches are the key advantage, so why switch to weak typing?. Weak typing basically defers Compile-Time errors till Run-Time. This allows a higher velocity of development since broken code doesn’t break the build but increases the burden of proof carried by Unit and System Tests.

Global

CAB Events are first class citizens because they do not require an object or even a class reference to scope them. This explicitly makes them global; another traditional enemy of ‘good code’. So why are we moving back the bad old days of global variables? Again this allows for faster development through limiting our choice of where we can define events. Which leads to the third benefit, with everything global, wiring things up couldn’t be easier…

Many Events – to – Many Subscribers

Every publisher of a given event ‘topic’ (as they’re refereed to) is automatically hooked up to every subscriber to that topic. A very useful trick. A similar thing can now be achieved using WPF attached properties but in .Net 2.0 CAB is your best option.

…and a nice touch

Although it’s not a key aspect of the CAB EventBroker system the ThreadOption parameter specified in the EventSubscription is a very nice touch which allows you to declarativly state which thread you want an event handler to run on. Very nice.

Conclusion

The EventBroker uses weak typing and global event definitions to allow for a faster development cycle using automatic many-to-many event/subscriber wiring. Try saying that 3 times fast…

Advertisements

One Response to Events in CAB (aka Composite UI App Block)

  1. […] to CABpedia As I was learning about CAB I stumbled across CABpedia. A MediaWiki instance devoted to Composite UI App Block. So […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: