example create middleware in web api .Net 6
public class MyMiddleware { private readonly RequestDelegate _next; public MyMiddleware(RequestDelegate next) { _next = next; } public async Task InvokeAsync(HttpContext context) { var a = 1; var b = 2; var c = a + b; // do something with c await _next(context); } }