Event Publication and Subscription

Topics: CAB & Smart Client Software Factory
Sep 29, 2005 at 7:14 AM
originally posted by: caldwelljr

I have a class that has an event publication and a subscription. The EventHandler variable is always null. Do I have to do something other than put the EventPublication and EventSubscription tags in the code? Here is a code snippet.

EventPublication("topic://DynaShell/ViewTenantScreen", EventScope.Global)
public event EventHandler<DataEventArgs<string>> TenantEvent;

public void ExplorerBarEvents(string key)
{
if (TenantEvent != null)
{
TenantEvent(this, new DataEventArgs<string>(key));
}
}

EventSubscription("topic://DynaShell/ViewTenantScreen", EventScope.Global)
public void ShowTenantScreen(object sender, DataEventArgs<string> args)
{
// processing logic...
}
Sep 30, 2005 at 5:41 AM
originally posted by: DLorenz

Why would you test (TenantEvent != null) ? You can't instantiate an Event... Don't you mean:

(Key.Length > 0) ?
Oct 1, 2005 at 5:20 AM
originally posted by: caldwelljr

Since I'm personally not in control of subscribing to the event handler I need to ensure the CAB did it's job. Also since the code is loosely coupled I will have no prior knowledge that someone actually will subscribe to the event (if it's not null, someone subscribed). This syntex is also supported by the CAB labs. The key variable is not relevant in this conversation, its just some metadata passed into the method.

BTW - I found the answer. First you must declare the EventPublication within a WorkItem. Then you must execute the CompositeContainer.Add() method (eg: WorkItem.Add(newWorkItem)). This actually forces the CAB to make all the necessary subscriptions based on common EventSubscription and EventPublication attributes.