Quantcast
Channel: patterns & practices: Prism
Viewing all articles
Browse latest Browse all 1878

New Post: Persistent Data on Events

$
0
0
Hi,

While the CompositePresentationEvent class does not provide this functionality by its own I think it's possible to use a custom event class in your application to do this without problems. For example, you could create the following base class that extends original the CompositePresentationEvent:
public class CompositePresentationEventWithPersistentPayload<T> : CompositePresentationEvent<T>
{
    public T LastMessage { get; private set; }

    public override void Publish(T payload)
    {
        this.LastMessage = payload;
        base.Publish(payload);
    }
}
That class defines a LastMessage property and overrides the Publish method to store the last payload used in it. If you change your event to inherit from this class, then you should be able to use it like this:
MyEvent myEvent = eventAggregator.GetEvent<MyEvent>();
myEvent.Publish(message);

// Now we can obtain the last message published thanks to the property.
var lastMessage = myEvent.LastMessage;
I hope this helps.

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

Viewing all articles
Browse latest Browse all 1878


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>