Last active
October 5, 2022 09:54
-
-
Save Ilchert/165df36ff6abd92223424575af8f6ad6 to your computer and use it in GitHub Desktop.
Aspnet minimal api filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.TestHost; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.WebHost.UseTestServer(); | |
var app = builder.Build(); | |
var group = app.MapGroup("/"); | |
group.AddEndpointFilter(async (efiContext, next) => | |
{ | |
var result = await next(efiContext); | |
if (result is IValueHttpResult valueResult) | |
return new { data = valueResult.Value }; | |
if (result is IResult) | |
throw new Exception("ХЗ чо делать"); | |
return new { data = result }; | |
}); | |
group.MapGet("/", () => Results.Ok(new { Name = "name" })); | |
await app.StartAsync(); | |
var client = app.GetTestClient(); | |
var response = await client.GetStringAsync(""); | |
Console.WriteLine(response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment