コード例 #1
0
        /// <summary>
        /// Bind an object to the object's type with specific initialization type and with supplied id as Key. This operation will ignore
        /// the [Singleton] or [Prototype] attributes that are declared in class attribute.
        /// </summary>
        /// <param name="type">Type of object to bind to.</param>
        /// <param name="obj">Target object.</param>
        /// <param name="instType">The initialization type.</param>
        /// <param name="id">Custom id of the object.</param>
        public void Bind <T>(T obj, InstantiationType instType, string id)
        {
            Type type = typeof(T);
            Dictionary <string, IoCObject> objectMap;

            if (!_objMap.TryGetValue(type, out objectMap))
            {
                objectMap = new Dictionary <string, IoCObject>();
            }

            objectMap[id] = new IoCObject(instType, obj);
            _objMap[type] = objectMap;
        }
コード例 #2
0
 /// <summary>
 /// Get the object with IoCObject. Returns the supplied object if instantiation type is singleton.
 /// Returns a cloned object of the supplied object if instantiation type is prototype.
 /// </summary>
 /// <returns></returns>
 public object GetObj(IoCObject iocObj)
 {
     if (iocObj.InstantiationType == InstantiationType.SINGLETON)
     {
         return(iocObj.Object);;
     }
     else if (iocObj.InstantiationType == InstantiationType.PROTOTYPE)
     {
         return(CloneObj(iocObj.Object));
     }
     else
     {
         return(null);
     }
 }