using System; namespace Mhf.Server.Common.Middleware { /// /// Implementation of a middleware /// public class MiddlewareStack { private MiddlewareDelegate _middlewareDelegate; public MiddlewareStack(MiddlewareDelegate kernel) { _middlewareDelegate = kernel; } public void Start(T user, TReq request, TRes response) { _middlewareDelegate(user, request, response); } public MiddlewareStack Use( Func, MiddlewareDelegate> middleware) { _middlewareDelegate = middleware(_middlewareDelegate); return this; } public MiddlewareStack Use(IMiddleware middleware) { return Use(next => (user, request, response) => middleware.Handle(user, request, response, next)); } } }