コード例 #1
0
        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);
        }
コード例 #2
0
        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;

        }
コード例 #3
0
ファイル: DIInstCreator.cs プロジェクト: xxq860725/Ctrip.SOA
        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);
        }
コード例 #4
0
 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;
 }
コード例 #5
0
        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>());
        }
コード例 #6
0
ファイル: DIInstCreator.cs プロジェクト: deboe2015/Ctrip.SOA
        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;
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 public object CreateInst(RegistObjectContext context, params object[] param)
 {
     return Activator.CreateInstance(context.ObjType, param);
 }
コード例 #9
0
 public RegistCheckResult Check(RegistObjectContext context)
 {
     return true;
 }
コード例 #10
0
ファイル: DIInstCreator.cs プロジェクト: deboe2015/Ctrip.SOA
        private bool HasCycle(RegistObjectContext context)
        {

            return false;
        }