コード例 #1
0
        static async Task Main()
        {
            var collection = ConfigureServices();
            var provider   = collection.BuildServiceProvider();

            dispatcher = provider.GetRequiredService <IDispatcher>();

            var command = AddNumbers(1, 5);

            var initialCommandResult = await dispatcher.ExecuteAsync <AddNumbersCommand, int>(command);

            var result = await initialCommandResult.MapToResultAsync(SuccessfulAdditionOfNumbers);

            result.DoWhenSuccessful(() => Console.WriteLine("Unexpectedly, we didn't break anything!"));
            result.DoWhenError(HandleError);
        }
コード例 #2
0
        public async Task InvokeAsync(
            HttpContext context,
            IDispatcher dispatcher,
            ILogger <BuskConsumerMiddleware> logger
            )
        {
            //*/
            if (context.Request.Path == $"/{Magic.VirtualPath.Consume}")
            {
                var cloudEvent = await context.Request.ReadCloudEventAsync();

                logger.LogInformation("Busk - Consuming event {Topic}", cloudEvent.Type);
                await dispatcher.ExecuteAsync(cloudEvent);

                context.Response.StatusCode = 500;
                return;
            }
            //*/
            await _next(context);
        }
コード例 #3
0
 private static async Task <Result> SuccessfulAdditionOfNumbers(int sum)
 {
     Console.WriteLine($"Command result is {sum}");
     return(await dispatcher.ExecuteAsync(Breaksomething));
 }