EventPublication and EventSubscription failing to connect

I'm having trouble getting EventPublication and EventSubscription to work. Things compile but the event goes nowhere, In the sample code below, EventHandler DoTrace is not being loaded by the system and so it is always a null object which makes it somewhat difficult for the event handler code to use it to publish the event to the subscribers.

Here's the essentials of the sample application which is simply sending a string to be passed to the Debug.WriteLine function. I've typed this in from memory so there could be a typo or two in there but the basic logic should be correct.

The original program was created using the new project -> WPF window application wizard. The event publication/subscription was added manually.

using System.Diagnostics;
using Microsoft.Practices.CompositUI.EventBroker;
using Microsoft.Practices.CompositUI.Utility;
namespace LoggingExperiment
{
public class Logger
{
[EventSubscription( "TopicTrace", ThreadOption.Publisher )]
public void DoTrace( object sender, DataEventArgs<string> e)
{
Debug.WriteLine( e.Data );
}
}
}

using System;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.CompositeUI.EventBroker;
using Microsoft.Practices.CompositeUI.Utility;

namespace LoggingExperiemnt
{
public partial class Window1 : System.Windows.Window
{
[EventPublication("TopicTrace", PublicationScope.Global)]
public event EventHandler<DataEventArgs<string>> DoTrace;

public WIndow1()
{
CallTrace(this, "Calling InitializeComponent");
InitializeComponent();
}

public void CallTrace( object sender, string msg )
{
if (DoTrace != null)
{
DoTrace( sender, new DataEventArgs<string>( msg ) );
}
}
}

The code compiles and runs butDoTrace is always null, indicating that the system never decided that it was necessary to establish the publish/subscriber relationship. What am I missing?

[2126 byte] By [RickLH] at [2008-1-8]
# 1

Hi Rick

EventBroker is not designed to be used outside of an application that is built on top of the CAB (Composite UI Application Block) which ships as part of the Smart Client Software Factory. The reason you are not seeing any of that wiring happen is because In a CAB application, Subscribers and Publishers are wired together as objects are instantiated by the underlying framework.

The WPF functionality provided in SCSF is for interop scenarios where you have a Windows Shell application that includes WPF components. If you are interested in using CAB in a pure WPF scenario, then I would recommend looking at the WPF/CAB extensions within SCSFContrib. The WPF/CAB wiki walks you through what you would need to do in order to upgrade an existing WPF application to use CAB. For a better understanding of CAB itself, I would download the factory which includes documentation and QuickStarts.

Regards

Glenn

GlennBlock[MSFT] at 2007-10-2 > top of Msdn Tech,Visual Studio Orcas,Windows Presentation Foundation (WPF)...

Visual Studio Orcas

Site Classified