Add publish/subscribe power to your .NET solution. Like magic.
(Ridiculously simple, but probably not the best solution for larger applications)
-
Create a message
public class HelloWorld : IMagicMessage { /* your stuff goes here */ }
-
Publish that message anywhere in your code
var messagebus = new MagicMessagebus(); messagebus.Publish(new HelloWorld());
-
Subcribe to that message anywhere in your code (static though)
public static void Subscribe(HelloWorld message) { /* anything you need done goes here */ }
-
๐ฐ
(Using Ninject as the Dependency Injector. Others will follow)
-
Bind the MagicMessagebus
kernel.Bind<IMagicMessagebus>().To<MagicMessagebus>().InSingletonScope();
-
Inject into your service
private readonly IMagicMessagebus messagebus; public FooService(IMagicMessagebus messagebus) { this.messagebus = messagebus; }
-
Publish your message
this.messagebus.Publish(new HelloWorld());
-
Subcribe to the message in any interface that's bound in Ninject
void Subscribe(HelloWorld message);
-
Implement that service
public void Subscribe(HelloWorld message) { /* anything you need done goes here */ }
-
๐ฐ๐ฐ