public Client(IConfigure configure) { //初始化中间件 middleWareHandler = new MiddleWareHandler <HttpContext>(); middleWare = new MiddleWare <HttpContext>(middleWareHandler); configure.Configure(middleWare); }
static MvcMiddleWare() { //初始化中间件 middleWareHandler = new MiddleWareHandler <ActionContext>(); middleWare = new MiddleWare <ActionContext>(middleWareHandler); Configure(middleWare); //载入缓存 LoadCache(); //初始化动作过滤器 InitActionFilter(); Console.WriteLine("启动成功。。。"); }
/// <summary> /// 初始化动作过滤器 /// </summary> private static void InitActionFilter() { actionMiddleWareHandler = new MiddleWareHandler <ActionMiddWareContext>(); actionMiddleWare = new MiddleWare <ActionMiddWareContext>(actionMiddleWareHandler); var filters = Configuration.Filters.Where(f => f.GetType().IsSubclassOf(typeof(ActionFilter))).ToList(); if (filters.Count > 0) { foreach (ActionFilter filter in filters) { actionMiddleWare.Add(async(context, next) => { filter.OnExecuting(context.ActionContext); await next(); filter.Executed(context.ActionContext); }); } } //实际要调用继续往下调用的中间件 actionMiddleWare.Add(async(context, next) => { await context.Action(); }); }