CAB EventAggregator Explanation

CAB, in terms of Composite Application block, published by Microsoft Pattern & Design team. today we try to learn the event aggregator design pattern included in CAB, which could help understand how it's designed and implemented.

As unusal, module would interact with other module or itself, so it needs to take a reference other module, couple-loosed. is there decouple-loose? The anser is true,Event Aggregator,which could resolve this problem, there three important parts, Publisher, Subscriber and EventAggregator.

  • Publisher, it just needs to publish its event and doesn't know the specific subscriber, and how many subscribers there are.
  • Subscriber, justs subscribe its care-about event, and doesn't know who's the publisher.
  • EventAggregator, just a transfer station, used to store all the subscribers for specific event. when publisher triggers its event, it would find all matched event to execute, within CAB, there are three different execution style.
    • Background Thread
    • UIThread 
    • Executing Thread

 

ExpandedBlockStart.gif IEvent Interface
 1       public   interface  IEvent < TPayload >
 2      {
 3          SubscriptionToken Subscribe(Action < TPayload >  action);
 4          SubscriptionToken Subscribe(Action < TPayload >  action, ThreadOption threadOption);
 5          SubscriptionToken Subscribe(Action < TPayload >  action,  bool  keepSubscriberReferenceAlive);
 6          SubscriptionToken Subscribe(Action < TPayload >  action, ThreadOption threadOption,  bool  keepSubscriberReferenceAlive);
 7          SubscriptionToken Subscribe(Action < TPayload >  action, ThreadOption threadOption,  bool  keepSubscriberReferenceAlive, Predicate < TPayload >  filter);
 8           void  Publish(TPayload payload);
 9           void  Unsubscribe(SubscriptionToken token);
10           void  Unsubscribe(Action < TPayload >  subscriber);
11           bool  Contains(SubscriptionToken token);
12           bool  Contains(Action < TPayload >  subscriber);
13      }

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/DivineEagle/archive/2011/02/15/1955061.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值