I am creating a demo version of Prism 2.1 to speed up with technology. I am having a problem with CompositePresentationEvents published and signed through an event aggregation service. Subscribing to a subscription works fine if I set a strong link (KeepSubscriberReferenceAlive = true), but it fails if I set a weak link (KeepSubscriberReferenceAlive omitted).
I would like to subscribe with a weak link, so I do not need to manage the unsubscribing from the event. Is there any way to do this? Why is a strong link required here? Thank you for your help!
Here are the details: My demo application is single-threaded and has two regions: Navigator and Workspace, as well as three modules NavigatorModule, WorkspaceAModule and WorkspaceBModule. NavigatorModule has two buttons: "Show workspace A" and "Show workspace B". When one of these buttons is pressed, ICommand is called, which publishes a CompositePresentationEvent named ViewRequested. The event contains a payload string that indicates which workspace module should be displayed.
Here is the announcement of the event from the infrastructure infrastructure project:
using Microsoft.Practices.Composite.Presentation.Events;
namespace Prism2Demo.Common.Events
{
public class ViewRequestedEvent : CompositePresentationEvent<string>
{
}
}
Here is the code for publishing events from the Navigator module:
var eventAggregator = viewModel.Container.Resolve<IEventAggregator>();
var viewRequestedEvent = eventAggregator.GetEvent<ViewRequestedEvent>();
viewRequestedEvent.Publish(workspaceName);
Here is the event subscription code that each Workspace module includes in its Initialize () method:
var eventAggregator = m_Container.Resolve<IEventAggregator>();
var viewRequestedEvent = eventAggregator.GetEvent<ViewRequestedEvent>();
viewRequestedEvent.Subscribe(this.ViewRequestedEventHandler, ThreadOption.PublisherThread, true);
The Subscribe () operator is displayed with a strong link.
Thanks again for your help.