Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public bool Subscribe <TEvent, TEventHandler>()
     where TEvent : IEventBase
     where TEventHandler : IEventHandler <TEvent>
 {
     return(_eventStore.AddSubscription <TEvent, TEventHandler>());
 }