示例#1
0
文件: ObjectPool.cs 项目: Epitomy/CMS
 public void Remove(ObjectKey key, object value)
 {
     if (this.Items.ContainsKey(key))
     {
         this.Items[key].Remove(value);
     }
 }
示例#2
0
文件: ObjectPool.cs 项目: Epitomy/CMS
        public void Add(ObjectKey key, object value)
        {
            if (this.Items.ContainsKey(key) == false)
            {
                this.Items.Add(key, new List<object>());
            }

            this.Items[key].Add(value);
        }
示例#3
0
文件: ObjectPool.cs 项目: Epitomy/CMS
 public void AddRange(ObjectKey key,List<object> items)
 {
     if (this.Items.ContainsKey(key))
     {
         this.Items[key].AddRange(items);
     }
     else
     {
         this.Items.Add(key, items);
     }
 }
示例#4
0
 public void AddRange(ObjectKey key, List <object> items)
 {
     if (this.Items.ContainsKey(key))
     {
         this.Items[key].AddRange(items);
     }
     else
     {
         this.Items.Add(key, items);
     }
 }
示例#5
0
文件: ObjectPool.cs 项目: Epitomy/CMS
 public List<object> this[ObjectKey key]
 {
     get
     {
         if (this.Items.ContainsKey(key))
         {
             return this.Items[key];
         }
         else
         {
             return null;
         }
     }
 }
示例#6
0
 public List <object> this[ObjectKey key]
 {
     get
     {
         if (this.Items.ContainsKey(key))
         {
             return(this.Items[key]);
         }
         else
         {
             return(null);
         }
     }
 }
示例#7
0
        private IEnumerable <object> ResolveInstances(ObjectKey key)
        {
            var list = this.ObjectPool[key];

            if (list == null)
            {
                list = new List <object>();
                foreach (var instance in ObjectContainer.CreateInstances(key.Type))
                {
                    list.Add(instance);
                }
                this.ObjectPool.AddRange(key, list);
            }


            return(list);
        }
示例#8
0
        private void RegisterInstance(ObjectKey key, object instance)
        {
            var list = Items[key];

            if (list == null)
            {
                lock (key)
                {
                    list = Items[key];
                    if (list == null)
                    {
                        list = new List <object>();
                        list.Add(instance);
                        Items.AddRange(key, list);
                    }
                }
            }

            list.Add(instance);
        }
示例#9
0
        private List <object> ResolveInstances(ObjectKey key)
        {
            var list = Items[key];

            if (list == null)
            {
                lock (key)
                {
                    list = Items[key];
                    if (list == null)
                    {
                        list = new List <object>();
                        foreach (var instance in ObjectContainer.CreateInstances(key.Type))
                        {
                            list.Add(instance);
                        }

                        Items.AddRange(key, list);
                    }
                }
            }

            return(Items[key]);
        }
示例#10
0
        public IEnumerable ResolveAll(Type type, string name)
        {
            var key = new ObjectKey(type, name);

            return(this.ResolveInstances(key));
        }
示例#11
0
        public IEnumerable ResolveAll(Type type)
        {
            var key = new ObjectKey(type, null);

            return(ResolveInstances(key));
        }
示例#12
0
        public object Resolve(Type type, string name)
        {
            var key = new ObjectKey(type, name);

            return(ResolveInstances(key).FirstOrDefault());
        }
示例#13
0
        public void RegisterInstance(Type type, string name, object instance)
        {
            var key = new ObjectKey(type, name);

            this.ObjectPool.Add(key, instance);
        }
示例#14
0
        public T Resolve <T>(string name)
        {
            var key = new ObjectKey(typeof(T), name);

            return((T)ResolveInstances(key).FirstOrDefault());
        }