Exemple #1
0
        private static async Task <object> PayloadFor(this HttpContext context, IRequestCommandHandler handler)
        {
            var payloadType = handler.GetType().GetInterfaces().Single(x => x.Name == typeof(IRequestCommandHandler <>).Name).GenericTypeArguments.Single();

            using var reader = new StreamReader(context.Request.Body);
            return((await reader.ReadToEndAsync()).Deserialize(payloadType));
        }
Exemple #2
0
 private static async Task <HttpStatusCode> Execute(this IRequestCommandHandler handler, Request request, object payload)
 {
     return(await(handler.GetType().GetMethod("HandleAsync") !.Invoke(handler, System.Reflection.BindingFlags.DoNotWrapExceptions, null, new[] { request, payload }, null) as Task <HttpStatusCode>) !);
 }
Exemple #3
0
        public static async Task Execute(this IRequestCommandHandler handler, RequestFactory requestFactory, HttpContext context)
        {
            context.Response.StatusCode = (int)await handler.Execute(requestFactory.Create(context), await context.PayloadFor(handler));

            await context.Response.CompleteAsync();
        }