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)); }
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)); }
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()); }