public bool Subscribe <TEvent, TEventHandler>() where TEvent : IEventBase where TEventHandler : IEventHandler <TEvent> { _eventStore.AddSubscription <TEvent, TEventHandler>(); var channelName = GetChannelName <TEvent, TEventHandler>(); //// TODO: if current client subscribed the channel //if (true) //{ _subscriber.Subscribe(channelName, async(channel, eventMessage) => { var eventData = eventMessage.ToString().JsonToType <TEvent>(); var handler = _serviceProvider.GetServiceOrCreateInstance <TEventHandler>(); if (null != handler) { await handler.Handle(eventData).ConfigureAwait(false); } }); return(true); //} //return false; }
public bool Subscribe <TEvent, TEventHandler>() where TEvent : class, IEventBase where TEventHandler : IEventHandler <TEvent> { _eventStore.AddSubscription <TEvent, TEventHandler>(); var channelName = GetChannelName <TEvent, TEventHandler>(); _subscriber.Subscribe(channelName, async(channel, eventMessage) => { var eventData = eventMessage.ToString().JsonToObject <TEvent>(); var handler = _serviceProvider.GetServiceOrCreateInstance <TEventHandler>(); if (null != handler) { await handler.Handle(eventData).ConfigureAwait(false); } }); return(true); }
public bool Subscribe <TEvent, TEventHandler>() where TEvent : IEventBase where TEventHandler : IEventHandler <TEvent> { return(_eventStore.AddSubscription <TEvent, TEventHandler>()); }