예제 #1
0
        /// <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;
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <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);
 }