How to publish Event via Prism EventAggregator?

1.5k views Asked by At

Currently im trying to implement an EventAggregator using prism to publish and subscribe events in between two modules.

I try to implement it in the way described here MSDN. But i stuck already at the begin.

I implemented an event in my Infrastructure namespace:

namespace Infrastructure
{
    public class MyAggregatorEvent : PubSubEvent<string>{}
}

In my first module i would like to publish/raise this event in the following way"

private PublishEvent()
{
    IEventAggregator _eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
    _eventAggregator.GetEvent<MyAggregatorEvent>().Publish("Test");
}

But the problem is that i cant call the Publish() method. I always get an error saying:

Infrastructure.MyAggregatorEvent' does not contain a definition for 'Publish' and no extension method 'Publish' accepting a first argument of type 'Infrastructure.MyAggregatorEvent' could be found (are you missing a using directive or an assembly reference?) D:\PviVm.cs ModulePvi

I read a lot of articles in the web but couldn't figure out what im doing wrong.

Has anybody an idea what im doing wrong?

1

There are 1 answers

0
ck84vi On

Finally i found the problem.

I mixed up the class references in my modules.

I used PubSubEvent Class in one module and CompositePresentationEvent Class in the other module. This was the root cause for my initial problem.

After using PubSubEvent in all my modules it works.