private async Task MutipleErrorsWithValueAndSeverityHandler(HttpRequest request, HttpResponse response, RouteData data) { var executor = new StaticFactoryMethod.Executor(); var result = executor.Operation(); if (result.Succeeded) { await response.WriteAsync($"Operation succeeded for number '{result.Value}."); } else { var json = JsonSerializer.Serialize(result); response.Headers["ContentType"] = "application/json"; await response.WriteAsync(json); } }
private async Task StaticFactoryMethodHandler(HttpRequest request, HttpResponse response, RouteData data) { // Create an instance of the class that contains the operation var executor = new StaticFactoryMethod.Executor(); // Execute the operation and handle its result var result = executor.Operation(); if (result.Succeeded) { // Handle the success } else { // Handle the failure } var json = JsonSerializer.Serialize(result); response.Headers["ContentType"] = "application/json"; await response.WriteAsync(json); }