public class AuthMiddleware { private readonly Func_next; public AuthMiddleware(AppFunc next) { _next = next; } public Task Invoke(IDictionary environment) { // Do authentication logic here _next.Invoke(environment); } }
public class LoggingMiddleware { private readonly AppFunc _next; public LoggingMiddleware(AppFunc next) { _next = next; } public async Task Invoke(IDictionaryIn the above example, the LoggingMiddleware class is a middleware that handles logging of HTTP requests and responses. It takes in the next middleware in the pipeline as a parameter in its constructor. When it receives a HTTP request, it logs the request details, invokes the next middleware in the pipeline and logs the response details. The AppFunc Invoke method is part of the OWIN specification and is included in the Microsoft.Owin package library.environment) { // Log request details here await _next.Invoke(environment); // Log response details here } }