Event publication and subcription

Topics: CAB & Smart Client Software Factory
May 9, 2006 at 5:02 AM
originally posted by: ramyap

Can I add publish an event and call it from a normal class (i.e a class which has no SmartPart attribute)

For Eg: I have a class called class1.cs which looks like

public class Class1
{
EventPublication("Event1", PublicationScope.Global)
public event EventHandler<EventArgs<string>> Event1;

.....
.....

public void MethodCall()
{
if (Event1 != null) // is always showing as null.
Event1(this, new EventArgs<string>("Test Message"));
}

}

Basically what is happening when i test the above code is, the 'Event1' event call is always null.
This event is subcribed in another class and has a handler.
But because the value is null, the event never gets fired.

Please let me know how to solve this issue.

Thanks.
May 9, 2006 at 1:36 PM
originally posted by: austinlamb

You need to make sure that this class (Class1, in your example) gets dependency-injected (via ObjectBuilder). ObjectBuilder is where the magic happens that hooks up event publications and subscriptions.

So you'd need something like (I'm not sure on the syntax here) : ObjectBuilder.BuildUpClass1("MyInstanceName")

(Note that I used and instead of angle-brackets for the generic method there, because the forum software doesn't play well with angle-brackets).