public RegistCheckResult Check(RegistObjectContext context) { var type = context.ObjType; var constructs = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); 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; }
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 RegistCheckResult Check(RegistObjectContext context) { var returnValue = new RegistCheckResult(); returnValue.IsPass = false; var objType = context.ObjType; ConstructorInfo[] constructs = objType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (constructs.Length != 1) { returnValue.Message = "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 = "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) { 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); }
internal ObjectPool(int poolMaxCount, IInstCreator creator, RegistObjectContext context, Action<object> action) { pool = new object[poolMaxCount]; this.maxCount = poolMaxCount; this.creator = creator; lastIndex = 0; this.context = context; }
private void SetContextInstType(InstType instType, RegistObjectContext context) { context.InstType = instType; context.InstCreator = InstCreatorFactory.Create(instType); var result = context.InstCreator.Check(context); if (result.IsPass == false) { throw new Exception("regist error:" + result.Message); } }
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) { if (context.Obj == null) { lock (_locker) { var diCreator = InstCreatorFactory.Create(IOCFactoryModel.InstType.Normal); var obj = diCreator.CreateInst(context, param); if (context.Obj == null) { context.Obj = obj; } } } return context.Obj; }
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) { 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>()); }
/// <summary> /// 注册 /// </summary> /// <param name="pType"></param> /// <param name="cType"></param> /// <param name="instType"></param> /// <param name="name"></param> public void Regist(Type pType, Type cType, InstType instType, string name) { Dictionary <string, RegistObjectContext> cDic = null; lock (dic) { if (string.IsNullOrEmpty(name)) { name = DEFAULTNAME; } try { cDic = dic[pType]; } catch (KeyNotFoundException) { dic.Add(pType, new Dictionary <string, RegistObjectContext>()); cDic = dic[pType]; } if (instType == InstType.Decorate) { throw new Exception(string.Format("Decorate Inst Not Allow Use Normal Regist Method To Regist")); } if (cDic.ContainsKey(name)) { throw new Exception(string.Format("Regist Type '{0}' Must be Unique", name)); } else { lock (cDic) { RegistObjectContext context = new RegistObjectContext(); context.ObjType = cType; context.PType = pType; this.SetContextInstType(instType, context); cDic.Add(name, context); } } } }
public object CreateInst(RegistObjectContext context, params object[] param) { var objType = context.ObjType; var index = 0; lock (_locker) { if (!this.cache.ContainsKey(objType)) { Type[] list; ConstructorInfo[] constructs = objType.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); 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(InstType.Normal); var returnValue = diCreator.CreateInst(context, inPArray); return returnValue; }
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>())); }
public object CreateInst(RegistObjectContext context, params object[] param) { var list = context.Params[ContextParamNameEnum.DECORATE_CONTEXTCHAIN] as List<RegistObjectContext>; object returnValue = null; foreach (var obj in list) { if (returnValue != null) { returnValue = obj.InstCreator.CreateInst(obj, returnValue); } else { returnValue = obj.InstCreator.CreateInst(obj); } } return returnValue; }
public RegistCheckResult Check(RegistObjectContext context) { return(true); }
public object CreateInst(RegistObjectContext context, params object[] param) { return(Activator.CreateInstance(context.ObjType, param)); }
public RegistCheckResult Check(RegistObjectContext context) { return true; }
private bool HasCycle(RegistObjectContext context) { return(false); }