예제 #1
0
        private object CreateInstance(RegistrationModel model, object[] arguments = null)
        {
            object returnedObj  = null;
            Type   typeToCreate = model.ObjectType;

            if (model.RegType == REG_TYPE.TRANSIENT)
            {
                returnedObj = AddTransientInstance.GetInstance().GetNewObject(typeToCreate, arguments);
            }
            else if (model.RegType == REG_TYPE.SINGLETON)
            {
                returnedObj = AddSingletonInstance.GetInstance().GetSingleton(typeToCreate, arguments);
            }

            return(returnedObj);
        }
예제 #2
0
        public object GetSingleton(Type t, object[] arguments = null)
        {
            object obj = null;

            try
            {
                if (objectPool.ContainsKey(t.Name) == false)
                {
                    obj = AddTransientInstance.GetInstance().GetNewObject(t, arguments);
                    objectPool.Add(t.Name, obj);
                }
                else
                {
                    obj = objectPool[t.Name];
                }
            }
            catch
            {
                // log it maybe
            }

            return(obj);
        }
예제 #3
0
 static AddTransientInstance()
 {
     instance = new AddTransientInstance();
 }