Click to Rate and Give Feedback
MSDN
MSDN Library
Client Development
Application Blocks
 Design of the Event Broker Service

  Switch on low bandwidth view
Smart Client Software Factory - April 2008
Design of the Event Broker Service

The Composite UI Application Block contains a set of interfaces and classes that comprise the eventbroker service. This enables you to implement loosely coupled communications between the components in your application. It is not designed for broadcasting or receiving events from outside of the application.

When adding a component to the container, the framework enters any events within the component that are marked as EventPublications, or methods marked as EventSubscriptions, into a catalog of events for that container. The WorkItem.EventTopics collection holds a collection of EventTopic instances, each of which defines the topic between an event source and its subscribers.

The Fire method of the appropriate EventTopic executes when an event annotated with the EventPublicationAttribute occurs. It identifies the subscribers to the event and raises the appropriate subscription methods. Figure 1 shows details of the event broker system within the Composite UI Application Block framework.

Cc540703.CABDesign4(en-us,MSDN.10).gif

Figure 1
The Event Broker System

This separates the design of the inspection strategy (using reflection on items added to the container) from the design of the EventTopics collection, because your own code might want to add, remove, or manage the topics, publications, and subscriptions programmatically.

Cc540703.note(en-us,MSDN.10).gifNote:
Any code can register a subscriber using the EventTopic class and subscriber code can potentially be malicious code running at a lower trust level than the application code. If your application accepts delegates from un-trusted sources, you should make sure you restrict the code access permissions available to delegate methods by using security permissions.

The EventSubscription can also receive a ThreadOption value specifying the threading options for calling the subscriber. The following options are available:

  • ThreadOption.Background. This option indicates that the handler should be called on a separate background thread.
  • ThreadOption.Publisher. This option is the default, and indicates that the handler should be called synchronously on the publisher’s thread.
  • ThreadOption.UserInterface. This option indicates that the handler should be called on the user interface thread, so it is safe for it to modify user interface elements.

The event broker implementation includes the following classes and interfaces:

  • EventTopic. Thisclass defines a topic between event sources and subscribers.
  • WorkItem. This class exposes the EventTopics collection that holds a list of the registered EventTopic instances for the application.
  • EventInspector. This class inspects objects and components for event publications and subscriptions, registers these publications and subscriptions in the EventTopic, and adds the EventTopic to the WorkItem.EventTopics collection. It also un-registers them when that component instance is disposed.

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker