Is there a way to enumerate items registered with the IEventAggregator

Topics: Prism v2 - WPF 3.5
Sep 10, 2009 at 6:44 PM
Edited Sep 10, 2009 at 7:09 PM

For example, I would like to do something akin to the following, in order to create a module who is capable of listening for and acting upon a group of CompositePresentationEvent(s), whose individual CompositePresentationEvent need not neccessarily be known at design time:

public class SomeClass
{
  public SomeClass(IEventAggregator aggregator)
  {
      foreach(var evt in aggregator.ResolveAll<SpecializedEvent>())
      {
           evt.Subscribe(someAction, ThreadOption.UIThread)
      }
  }
}

public class SpecializedEvent : CompositePresentationEvent<string> { } public class MyEvent1 : SpecializedEvent { } public class SomeFutureEvent : SpecializedEvent { }

 

 

Sep 10, 2009 at 10:50 PM

Hi Bill,

There is no out-of-the-box way to achieve this kind of functionality in Prism-v2. The approach I would recommend is creating something like SpecializedEvent: CompositePresentationEvent<SpecializedEventArgs>. Instead of having a generic kind of event, the SpecializedEventArgs should provide the information that will enable you to filter the events that were originally meant for MyEvent1 using subscription filters (explained here).

A possible sample implementation for SpecializedEventArgs could be something like:

public class SpecializedEventArgs
{
public string Value { get; set; }
public EventKind Kind { get; set; }

}

public enum EventKind
{
MyEvent1,
MyFutureEvent,
}

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman