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 void Test() { Booking booking = new Ctrip(); Booking railway = new RailwayStation(); Assert.Equal(railway.BuyTicket(), booking.BuyTicket()); }
public object CreateInst(Ctrip.SOA.Infratructure.IOCFactoryModel.RegistObjectContext context, params object[] param) { if (context.Obj == null) { lock (context) { var diCreator = InstCreatorFactory.Create(Ctrip.SOA.Infratructure.IOCFactoryModel.InstType.DI); context.Obj = diCreator.CreateInst(context, param); } } return context.Obj; }
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); }