public object CreateInst(RegistObjectContext context, params object[] param)
        {
            var types = new Type[param.Length];

            for (int i = 0; i < param.Length; i++)
            {
                types[i] = param[i].GetType();
            }

            ObjectActivator objectCreater;
            try
            {
                objectCreater = dicCache[context.HashCode];
            }
            catch (KeyNotFoundException)
            {
                lock (dicCache)
                {
                    var constructor = context.ObjType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, types, null);
                    dicCache.Add(context.HashCode, NormalInstCreator.GetActivator(context.ObjType, constructor));
                    objectCreater = dicCache[context.HashCode];
                }
            }
            return objectCreater(param);
        }
        public RegistCheckResult Check(RegistObjectContext context)
        {
            var type = context.ObjType;
            var constructs = type.GetConstructors();
            var returnValue = new RegistCheckResult();
            returnValue.IsPass = false;
            if (constructs.Length != 1)
            {
                returnValue.Message = string.Format("type regist as decorate must and only have 1 construct method");
                return returnValue;
            }
            var contruct = constructs[0];

            var parameters = contruct.GetParameters();

            if (parameters.Length != 1)
            {
                returnValue.Message = string.Format("type regist as decorate the construct method must and only have 1 param ");
                return returnValue;
            }

            var parameter = parameters[0];

            if (parameter.ParameterType != context.PType)
            {
                returnValue.Message = string.Format("type regist as decorate the construct method's param must be {0}", context.PType.Name);
                return returnValue;
            }

            returnValue.IsPass = true;
            return returnValue;

        }
Beispiel #3
0
        public RegistCheckResult Check(Ctrip.SOA.Infratructure.IOCFactoryModel.RegistObjectContext context)
        {
            var returnValue = new RegistCheckResult();

            returnValue.IsPass = false;

            var objType = context.ObjType;

            ConstructorInfo[] constructs = objType.GetConstructors();
            if (constructs.Length != 1)
            {
                returnValue.Message = string.Format("regist as DI Inst must and only have 1 construct method");
                return(returnValue);
            }

            var construct = constructs[0];

            var pArray = construct.GetParameters();

            foreach (var p in pArray)
            {
                if (!p.ParameterType.IsInterface)
                {
                    returnValue.Message = string.Format("regsit as DI Inst the construct method's paramters must be interface type");
                    return(returnValue);
                }
            }
            return(true);
        }
 public object CreateInst(RegistObjectContext context, params object[] param)
 {
     if (context.Obj == null)
     {
         lock (context)
         {
             var diCreator = InstCreatorFactory.Create(Ctrip.SOA.Infratructure.IOCFactoryModel.InstType.Normal);
             context.Obj = diCreator.CreateInst(context, param);
         }
     }
     return context.Obj;
 }
        public object CreateInst(RegistObjectContext context, params object[] param)
        {
            var types = new Type[param.Length];

            for (int i = 0; i < param.Length; i++)
            {
                types[i] = param[i].GetType();
            }

            var constructor = context.ObjType.GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, types, null);
            if (!dicCache.ContainsKey(context.ObjType))
            {
                dicCache.Add(context.ObjType, NormalInstCreator.GetActivator(context.ObjType, constructor));
            }
            var objectCreater = dicCache[context.ObjType];

            return objectCreater(param.ToArray<Object>());
        }
Beispiel #6
0
        public object CreateInst(RegistObjectContext context, params object[] param)
        {
            var objType = context.ObjType;

            var index = 0;

            if (!this.cache.ContainsKey(objType))
            {
                lock (this.cache)
                {
                    Type[] list;

                    ConstructorInfo[] constructs = objType.GetConstructors();
                    var construct = constructs[0];
                    var pArray = construct.GetParameters();
                    list = new Type[pArray.Length];

                    foreach (var p in pArray)
                    {
                        list[index] = p.ParameterType;
                        index++;
                    }
                    this.cache.Add(objType, list);
                }
            }

            Type[] types = this.cache[objType];

            var factory = Factory.GetInst();

            var inPArray = new object[types.Length];
            index = 0;
            foreach (Type t in types)
            {
                inPArray[index] = factory.Get(t);
                index++;
            }

            var diCreator = InstCreatorFactory.Create(Ctrip.SOA.Infratructure.IOCFactoryModel.InstType.Normal);

            var returnValue = diCreator.CreateInst(context, inPArray);
            return returnValue;
        }
        public object CreateInst(RegistObjectContext context, params object[] param)
        {
            object returnValue = null;
            if (!context.Params.ContainsKey(ContextParamNameEnum.TODECORATENAME))
            {
                throw new Exception("Error InstType");
            }
            Factory factory = Factory.GetInst();
            var toDecorateName = context.Params[ContextParamNameEnum.TODECORATENAME].ToString();
            var toDecorateObj = factory.Get(context.PType, toDecorateName);
            var instList = (List<Type>)context.Params[ContextParamNameEnum.INSTCHAIN];

            var diCreator = InstCreatorFactory.Create(Ctrip.SOA.Infratructure.IOCFactoryModel.InstType.Normal);

            foreach (var type in instList)
            {
                toDecorateObj = diCreator.CreateInst(new RegistObjectContext() { ObjType = type }, toDecorateObj);
            }
            returnValue = toDecorateObj;
            return returnValue;
        }
 public object CreateInst(RegistObjectContext context, params object[] param)
 {
     return Activator.CreateInstance(context.ObjType, param);
 }
 public RegistCheckResult Check(RegistObjectContext context)
 {
     return true;
 }
Beispiel #10
0
        private bool HasCycle(RegistObjectContext context)
        {

            return false;
        }