示例#1
0
文件: TestBase.cs 项目: wmadzha/Chill
        /// <summary>
        /// Get a value from the container, identified by the name. This should have been set by using <see cref="StoreStateBuilderExtensions.Named{T}"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="named"></param>
        /// <returns></returns>
        public T TheNamed <T>(string named)
            where T : class
        {
            var items = Container.Get <Dictionary <Tuple <Type, string>, object> >();
            var key   = Tuple.Create(typeof(T), named);

            object item;

            if (!items.TryGetValue(key, out item))
            {
                item = Container.Get <T>(named);
                items.Add(key, item);
                container.Set(items);
            }
            return((T)item);
        }
示例#2
0
        /// <summary>
        /// chill keeps a list of registered items in memory. This method get's that list.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="container"></param>
        /// <returns></returns>
        internal static List <T> GetList <T>(this IChillContainer container) where T : class
        {
            var dictionary = container.Get <Dictionary <Type, object> >();


            if (dictionary == null || dictionary.Count == 0)
            {
                dictionary = new Dictionary <Type, object>();
            }

            object list;

            if (!dictionary.TryGetValue(typeof(T), out list))
            {
                list = new List <T>();
                dictionary.Add(typeof(T), list);
                container.Set(dictionary);
            }
            return((List <T>)list);
        }
 /// <summary>
 ///     Sets the specified value to set.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="valueToSet">The value to set.</param>
 /// <param name="key">The key.</param>
 /// <returns></returns>
 public T Set <T>(T valueToSet, string key = null) where T : class
 {
     return(internalChillContainer.Set(valueToSet, key));
 }