I'm new to asp.net core, sorry if my question sounds dumb. In asp.net core 3, we can implement a custom middleware as simple as:
public class CustomMiddleware
{
private RequestDelegate next;
public CustomMiddleware (RequestDelegate nextDelegate) {
next = nextDelegate;
}
public async Task Invoke(HttpContext context) {
...
}
}
so our custom middlewares don't need to implement an interface such as IMiddleware or inherit from an abstract base Middleware class, which is a little bit strange to me. Because for some other thing like controller, we have public class HomeController : ControllerBase. So why Microsoft not setup a strong type interface/abstract class for custom middleware, for example,
public abstract class BaseMiddleware {
public BaseMiddleware(RequestDelegate nextDelegate) {
next = nextDelegate;
}
public abstract async Task Invoke(HttpContext context);
}
so that our custom middleware can be:
public class CustomMiddleware : BaseMiddleware
{
public CustomMiddleware(RequestDelegate nextDelegate) : base(nextDelegate) {}
public override async Task Invoke(HttpContext context) {
...
}
}