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); }
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 void RegistFromFile(string filePath, FactoryMappingFilePattern pattern = FactoryMappingFilePattern.Normal) { if (File.Exists(filePath)) { var contextReader = InstCreatorFactory.GetReader(pattern); var contexts = contextReader.GetMappingContexts(filePath); this.RegistUseMappingContext(contexts); } else { throw new FileNotFoundException("fileNotFound", filePath); } }
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 Ctrip.SOA.Infratructure.IOCFactoryModel.RegistCheckResult Check(Ctrip.SOA.Infratructure.IOCFactoryModel.RegistObjectContext context) { var diCreator = InstCreatorFactory.Create(Ctrip.SOA.Infratructure.IOCFactoryModel.InstType.DI); return(diCreator.Check(context)); }