예제 #1
0
        private static Task ExecuteEventAsync <TEvent>(CqrsProcessor processor, Context context)
            where TEvent : IEvent
        {
            var dispatcher   = processor._strategy.GetDispatcher(context) ?? throw NoDispatcherError();
            var notification = GetRequestOrThrow(processor, context, typeof(TEvent));

            return(dispatcher.PublishAsync((TEvent)notification, context.Aborted));
        }
예제 #2
0
        private static Task ExecuteCommandAsync <TRequest, TResult>(CqrsProcessor processor, Context context)
            where TRequest : ICommand <TResult>
        {
            var dispatcher = processor._strategy.GetDispatcher(context) ?? throw NoDispatcherError();
            var command    = GetRequestOrThrow(processor, context, typeof(TRequest));

            return(dispatcher.ProcessAsync((TRequest)command, context.Aborted));
        }
예제 #3
0
        private static object GetRequestOrThrow(CqrsProcessor processor, Context context, Type type)
        {
            var formatter = processor._strategy.GetRequestFormatter(context) ?? throw NoRequestFormatterError();

            return(formatter.Deserialize(context.Request.Content, type) ?? throw NoRequestError());
        }