EventAgregator

Apr 3, 2012 at 8:26 PM

hello all
I'm trying to understand how the EventAgregator works
I'm reading and studying for several hours ... 

I only found examples that do not help me ... all is very articulate ...
can you have a simple example?
thanks

 
 
 
Developer
Apr 3, 2012 at 8:58 PM

Hi,

I believe you can find the EventAggregation QuickStart provided with the VB version of Prism useful. This QuickStart portrays a simple scenario that uses the EventAggregator to communicate between two presenters defined in different modules.

  • The ActivityPresenter in the ModuleB subscribes / unsubscribes to the FundAddedEvent when its CustomerId property changes.
  • The AddFundPresenter in the ModuleA publishes a FundAddedEvent when the "Add" button is pressed in its corresponding view.
  • When the FundAddedEvent is published, the FundAddedEventHandler of the corresponding ActivityPresenter is invoked due to the previous registration to that event through the EventAggregator.

Also, you can find the FundAddedEvent in the EventAggregation.Infrastructure project of the QuickStart.

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Apr 3, 2012 at 9:56 PM
thank you very much
your instructions are very useful
sorry ... one more question
I can apply what you suggested
Also using mef?
thanks
 
 
 
Apr 4, 2012 at 4:55 AM

Hi ... sorry
maybe 'stupid
all about 'topic events
but if I declare a global static class of my application
for example

Imports Microsoft.Practices.Prism.Events

Public Class Events
Private Shared _Event As New EventAggregator
Public Shared ReadOnly Property EVAG () As EventAggregator
Get
Return _Event
end Get
end Property
end Class

and then I create the following method to publish an event
Events.EvAg.GetEvent (Of EventoUtente) (). Publish ("Test")

and then I create the following method to subscribe to the 'event Events.EvAg.GetEvent (Of EventoUtente). Subscribe (AddressOf Eventos, ThreadOption.UIThread)

definitely a bit ugly but simple
what do you think?
you have any suggestions?
thank you very much

 

 

 
 
 

 

Developer
Apr 4, 2012 at 5:29 PM

Hi,

As far as I know, Unity or MEF can be used as dependency injection containers with Prism as out of the box. This means that you should be able to use any of the capabilities provided by Prism (including EventAggregator) with any of the two aforementioned containers.

Regarding the code snippet, which approach you should use to access the EventAggregator will depend mostly of your personal preferences and the requirements of your scenario. The approach you are mentioning of wrapping the EventAggregator using a static class seems to be a valid one.

Another possibility to access the default EventAggregator in your application could be to retrieve it using the ServiceLocator service. You can find more information about this in the following chapter of the Prism documentation:

I hope you find this useful,

Damian Cherubini
http://blogs.southworks.net/dcherubini

Apr 5, 2012 at 8:04 AM

thank you very much for your suggestions

very very useful

thanks