Skip to content
flq edited this page Feb 7, 2012 · 14 revisions

MemBus is available through NuGet

Information can also be obtained through the blog posts on my site tagged membus.

Quick Example

public void Start() {
  IBus b = BusSetup.StartWith<Conservative>()
           .Apply<FlexibleSubscribeAdapter>(c=>c.ByMethodName("Handle"))
           .Construct();
  using (b.Subscribe(this)) {
    b.Publish("Hello World");
  }
}

public void Handle(string message) {
  Console.Writeline(message);
}
  • Setting up MemBus with conservative settings: No multithreading, linear sequential publication of messages

  • Applying the Setup part FlexibleSubscribeAdapter - it needs some additional info, namely that for instances you subscribe, you want to look for methods taking a single argument and being called Handle.

  • Construct a Bus instance from this setup.

  • Subscribe through the method accepting an object. This will subscribe any Handle methods hence becoming subscriptions to the type of the message specified by the method, in this case a string. The return value is a disposable that, when enacted, disposes of the subscription - it will no longer receive messages.

  • Publish a message that fits the Handle signature.

If the handle would accept an object, it would also be called, since messaging in MemBus is in general contravariant.

Anything could be a message. You are unlikely to just send strings around, but you can.

Then there have been anumber of blog posts, which will in the coming time be distilled into Wiki pages over here. For now I point you to Content tagged MemBus

Other Examples

Clone this wiki locally