Event Aggreation: Getting Started

Topics: Prism v2 - WPF 3.5
Nov 11, 2009 at 6:38 AM

Hi there,

I am a Prism newbie and do not understand how to get Event Aggregation wired up.

I have a shell project and two module projects. When a view is closed any of the modules I want to pass the Viewname to the Shell project which Removes the View.

From other reading I understand I need to:

1) Create an event deriving from CompositePresentationEvent and include that in my Shell Project.

2) Publish the event in my module project

3) Subscribe to the event in my Shell Project

But, how does my module project know about the CompositePresentationEvent in my Shell project ?

Could someone provide the basic wire-up code that show how a module project knows about the CompositePresentationEvent class in the Shell project ?

My CompositePresentationEvent is called CloseViewEvent

My Payload class is called ViewInfo

 

 

Nov 11, 2009 at 8:27 AM
Edited Nov 11, 2009 at 8:28 AM

Most people tend to create an Infrastructure project in VS to hold common information like events, Entity objects, services that are needed by multiple modules and the shell.   I tend to include this infrastructure project in all other VS projects that need to reference common items.  

In the shell I use code like below to get the EventAggregator to then in your case subscribe to the event

IEventAggregator agg = Container.Resolve<IEventAggrigator>();

In the modules I use constructor injection to get the IEventAggregator to then in your case, publish the event

e.g. public xxxModule(IEventAggregator agg)

This works well for smaller applications but for larger apps you could consider creating for each module a static core class in which you could also declare common information.  However for all my apps so far I have added an infrastructure VS module

Hope this helps

Nov 11, 2009 at 3:16 PM

Did yo manage to check EventAggregation sample in Quick Start?

Nov 11, 2009 at 10:33 PM

SwissSteve

Thanks for that.

I didn't realise that the Infrastructure Project and the Shell Project were seperate concepts!

Got it working now