Last active
August 29, 2015 14:07
-
-
Save beufordy3k/96a2c33a3f4a533e55fc to your computer and use it in GitHub Desktop.
Prism IEventAggregator Generic subscription service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using TestApp.Interfaces; | |
using Microsoft.Practices.Prism.PubSubEvents; | |
namespace TestApp.Services | |
{ | |
public class EventSubscriberService : IEventSubscriberService, IDisposable | |
{ | |
private readonly IEventAggregator m_eventAggregator; | |
private Dictionary<SubscriptionToken, Type> m_subscriptions; | |
public EventSubscriberService(IEventAggregator eventAggregator) | |
{ | |
m_eventAggregator = eventAggregator; | |
m_subscriptions = new Dictionary<SubscriptionToken, Type>(); | |
} | |
public void Subscribe<T, U>(string moduleName, Action<U> eventAction, ThreadOption threadOption) where T : PubSubEvent<U>, new() | |
{ | |
var subscriptionToken = m_eventAggregator.GetEvent<T>().Subscribe(eventAction, threadOption, true); | |
m_subscriptions.Add(subscriptionToken, typeof(T)); | |
} | |
public void Dispose() | |
{ | |
foreach (var item in m_subscriptions) | |
{ | |
//Do Something | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Microsoft.Practices.Prism.PubSubEvents; | |
namespace TestApp.Interfaces | |
{ | |
public interface IEventSubscriberService | |
{ | |
void Subscribe<T, U>(string moduleName, Action<U> eventAction, ThreadOption threadOption) where T : PubSubEvent<U>, new(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment