-
Notifications
You must be signed in to change notification settings - Fork 24
Examples
SoftLattice is UI framework in the works, based on a number of technologies and putting messaging at its heart. The following is a snapshot of the Membus configuration set up there:
private static IBus constructBus()
{
return BusSetup.StartWith<AsyncRichClientFrontend>(
new IoCSupport(new StructuremapBridge(() => ObjectFactory.Container)))
.Apply<FlexibleSubscribeAdapter>(c=>c.ByMethodName("Handle").ByInterface(typeof(IHandles<>)))
.Apply<ActivateViewModelMessagesGoThroughViewActivationPump>()
.Construct();
}
private class ActivateViewModelMessagesGoThroughViewActivationPump : ISetup<IConfigurableBus>
{
public void Accept(IConfigurableBus setup)
{
setup.ConfigurePublishing(PublishPipelineForViewActivationMessages);
}
private static void PublishPipelineForViewActivationMessages(IConfigurablePublishing obj)
{
obj.MessageMatch(mi=>mi.IsType<ActivateViewModelMsg>()).PublishPipeline(
new DeferredPublishPipelineMember<ViewActivationPump>(ObjectFactory.GetInstance<ViewActivationPump>),
new SequentialPublisher());
}
}
In essence, messages will be processed asynchronously, i.e. subscribers will often have to deal with dispatching. Even though you could delegate this to Membus, the Rx Framework makes it very easy to do that.
It is ensured that object subscriptions will be subscribed by either implementing IHandles or defining a Handle method. Of course an object may define many Handle methods or implement the interface several times with a different generic.
Finally an individual setup comes into place. A different publish pipeline runs for any messages assignable to ActivateViewModelMsg. The message will go though a ViewActivation pump which essentially takes a viewmodel type defined in the message, instantiates the type, and puts it into the corresponding value of the message.