DefaultMessageManager Only Uses One EventHandler

Topics: Writing modules
Dec 21, 2011 at 3:45 AM

Why does the DefaultMessageManager class only use one IMessageEventHandler?

Seems like it should be firing all the event handlers, or am I wrong?  If not, is there a convention on which event handler is used in these scenarios?  

Dec 21, 2011 at 3:56 AM

There's an intercept in Autofac. It proxies the call to a single IEventHandler so it actually calls *all* of them.

So, any time you import a dependency that inherits from IEventHandler, you don't need to use an IEnumerable, just import a single instance and it'll actually trigger all of them.

Dec 21, 2011 at 4:00 AM

Ah! Ok, I didn't realize that.  Thanks.

Dec 21, 2011 at 4:04 AM

It's because those instances might not actually be the same class; the message bus will fire the event on any interface with the same name and same method.

Dec 21, 2011 at 4:07 AM

This makes sense since it's an Event Bus.  You wouldn't want to be missing messages.  Haha.  I just didn't realize it worked without the explicit IEnumerable.  That's pretty cool. 

Dec 21, 2011 at 4:13 AM

Just curious if it still works the same if you do use the IEnumerable<IMessagaeEventHandler>.  Would it still fire the handlers that "look like a duck"?  If you don't know off the top of your head, I'll just test it I guess, haha.

Dec 21, 2011 at 9:03 AM

The IEnumerable will only contain 1 element, which will be the same proxy to all the receivers.

Dec 21, 2011 at 5:26 PM

Very cool.  Thanks for the clarification on that.