/// <summary> /// Give the alias of the middleware /// </summary> /// <param name="middleware"></param> /// <returns></returns> public static string GetAlias(Middleware middleware) { if (middlewarePair.Count == 0) return null; foreach (KeyValuePair<string, Middleware> pair in middlewarePair) { if (pair.Value == middleware) return pair.Key; } return null; }
/// <summary> /// Append a middleware instance to the global container /// </summary> /// <param name="alias">The alias of the instance that used to reference a middleware instance /// when register a middleware in the somewhere. /// </param> /// <param name="middleware">A instance of the middleware</param> /// <param name="priority">The highest priority of middleware will be handle first</param> public static void Add(string alias, Middleware middleware, int priority) { if (TextUtils.isEmpty(alias) || middleware == null) return; middleware.Priority = priority; if (middlewarePair.ContainsKey(alias)) { middlewarePair[alias] = middleware; } else { middlewarePair.Add(alias, middleware); } // Resort the middleware list middlewarePair = middlewarePair.OrderByDescending(p => p.Value.Priority) .ToDictionary(p => p.Key, p => p.Value); }
/// <summary> /// Append a middleware instance to the global container /// </summary> /// <param name="alias">The alias of the instance that used to reference a middleware instance /// when register a middleware in the somewhere. /// </param> /// <param name="middleware">A instance of the middleware</param> public static void Add(string alias, Middleware middleware) { Add(alias, middleware, 0); }