Once I have worked with Orchard CMS. Orchard has well implemented features. One of most liked by me is event system.
How it works?
Consider I have interface that represents some events:
So let’s create some handlers:
And… that’s all! The Event bus system automatically searches for implementations, resolves it with the current dependency resolver and calls proper methods. Magic!
How Can I achieve it?
The first step is to create a proxy class for interfaces, that automatically invokes all implementations. I have used Castle.DynamicProxy for it:
(part of classes are skipped).
But alone proxy is not enough - we need to integrate it with some dependency injection library.
I have chosen my favourite - AutoFac:
What do you think about it?
Full code available on github.