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); }
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); }
private static async Task <Result> SuccessfulAdditionOfNumbers(int sum) { Console.WriteLine($"Command result is {sum}"); return(await dispatcher.ExecuteAsync(Breaksomething)); }