/// <summary> /// /// </summary> /// <typeparam name="TFrom"></typeparam> /// <typeparam name="TTo"></typeparam> /// <param name="lifeTimeType">默认参数,不传递就是Transient</param> public void RegisterType <TFrom, TTo>(LifeTimeType lifeTimeType = LifeTimeType.Transient) { ContainerDictionary.Add(typeof(TFrom).FullName, new RegisterInfo() { TargetType = typeof(TTo), LifeTime = lifeTimeType }); }
/// <summary> /// 注册实现类 /// </summary> /// <typeparam name="TFrom">抽象接口</typeparam> /// <typeparam name="TTo">具体实现类</typeparam> /// <param name="shortName"></param> public void Register <TFrom, TTo>(string shortName = null, object[] paraList = null, LifeTimeType lifeTimeType = LifeTimeType.Transient) where TTo : TFrom { this.ContainerDictionary.Add(this.GetKey(typeof(TFrom).FullName, shortName), new ContainerRegistModel() { TargetType = typeof(TTo), LifeTime = lifeTimeType }); if (paraList != null && paraList.Length > 0) { this.ParaListDictionary.Add(this.GetKey(typeof(TFrom).FullName, shortName), paraList); } }
/// <summary> /// 注册 /// </summary> /// <typeparam name="TFrom">归属寄存器</typeparam> /// <typeparam name="TTo">实现类</typeparam> /// <param name="alias">归属寄存器别名</param> /// <param name="values">构造指定参数值</param> /// <param name="lifeTimeType">生命周期类型</param> public void Register <TFrom, TTo>(string alias = null, object[] values = null, LifeTimeType lifeTimeType = LifeTimeType.Transient) where TTo : TFrom { alias = ObtainAlias(typeof(TFrom), alias); if (_registerDictionary.ContainsKey(alias)) { throw new Exception("Don't repeat registration!Try add and alias for the interface!"); } _registerDictionary.Add(alias, new BPIOCRegister() { RegisterLifeTime = lifeTimeType, RegisterType = typeof(TTo), ValueTypeArray = values }); }
public RegisterInfo(Type targetType, LifeTimeType lifeTime) { this.TargetType = targetType; this.LifeTime = lifeTime; }
public void RegisterType <TFrom, TTo>(LifeTimeType lifeTimeType = LifeTimeType.Transient) { this._Container[typeof(TFrom).FullName] = new RegisterInfo(typeof(TTo), lifeTimeType); }
public void Register <TFrom, TTo>(string shortname = null, object[] paramlist = null, LifeTimeType lifeTimeType = LifeTimeType.Transient) where TTo : TFrom { //string key = typeof(TFrom).FullName; string key = GetKey(typeof(TFrom).FullName, shortname); if (paramlist != null && paramlist.Length > 0) { if (!DIPContainerValueDic.ContainsKey(key)) { DIPContainerValueDic.Add(key, paramlist); } else { DIPContainerValueDic[key] = paramlist; } } if (DIPContainerDic.ContainsKey(key)) { DIPContainerDic[key] = new RegisterModel() { LifeType = lifeTimeType, ModelType = typeof(TTo) }; } else { DIPContainerDic.Add(key, new RegisterModel() { LifeType = lifeTimeType, ModelType = typeof(TTo) }); } }
public InjectableAttribute(Type targetType, LifeTimeType lifetimeManager) { TargetType = targetType; LifetimeManager = lifetimeManager; }
public InjectableAttribute(LifeTimeType lifetimeManager) : this(null, lifetimeManager) { }