Exemplo n.º 1
0
        public void SubscribeToEvent <TEvent>(EventReceivedAsync <TEvent> eventReceived)
            where TEvent : class, IEvent
        {
            _engine.SubscribeToEvent <TEvent>();

            _errorHandlers.AddOrUpdate(typeof(TEvent), CreateEventErrorDelegate <TEvent>(), (key, item) => item);

            _messagePipelines.Add(async message =>
            {
                if (message is EventMessage <TEvent> eventMessage)
                {
                    var dispatcher = new NybusDispatcher(this, eventMessage);
                    var context    = new NybusEventContext <TEvent>(eventMessage);
                    await eventReceived(dispatcher, context).ConfigureAwait(false);
                }
            });
        }
Exemplo n.º 2
0
        public void SubscribeToCommand <TCommand>(CommandReceivedAsync <TCommand> commandReceived)
            where TCommand : class, ICommand
        {
            _engine.SubscribeToCommand <TCommand>();

            _errorHandlers.AddOrUpdate(typeof(TCommand), CreateCommandErrorDelegate <TCommand>(), (key, item) => item);

            _messagePipelines.Add(async message =>
            {
                if (message is CommandMessage <TCommand> commandMessage)
                {
                    var dispatcher = new NybusDispatcher(this, commandMessage);
                    var context    = new NybusCommandContext <TCommand>(commandMessage);
                    await commandReceived(dispatcher, context).ConfigureAwait(false);
                }
            });
        }