MBS 重新设计和实现了 CAB (Composite UI Application Block) 同时集成了消息总线、IoC 以及 UI 插件。
消息总线的例子:
1. string of message content var MB = new MessageBus();//create message bus var unsubscriber = MB.Subscribe((s,e)=>Console.WriteLine(e));//subscribe the string of message content MB.Publish(“hello Message Bus!”);//public the string of message content unsubscriber.Dispose();//un subscribe
2. int type of message var MB = new MessageBus();//create message bus var unsubscriber = MB.Subscribe((s,e)=>Console.WriteLine(e));//subscribe int message type MB.Publish(521);//publish unsubscriber.Dispose();//unsubscribe
3. User defined Message public class Person { public string Name { get;set;} public int Age { get;set;} public bool Sex { get;set;} }
var MB = new MessageBus();//create message bus var unsubscriber = MB.Subscribe((s,e)=>Console.WriteLine(e.Name));// subscribe Persion Message (the output is Persion.Name) MB.Publish(new Person { Name = “ZhangSan”});//publish Person Message unsubscriber.Dispose();//unSubscribe