/// <summary> /// Registers single generic Type. LifeTime options can be used. /// </summary> public void Register <TImplementation>(LifeTimeStyle lsType) where TImplementation : class { if (!typeof(TImplementation).IsClass || typeof(TImplementation).IsAbstract) { throw new Exception(string.Format("Single generics needs to be only concrete classes. Name: {0}", typeof(TImplementation).FullName)); } Register <TImplementation, TImplementation>(lsType); }
/// <summary> /// Registers Type with the concrete implementation. LifeTime options can be used. /// </summary> public void Register <TContract, TImplementation>(LifeTimeStyle lsType) where TContract : class where TImplementation : class { if (types.ContainsKey(typeof(TContract))) { throw new Exception(string.Format("Type {0} already registered.", typeof(TContract).FullName)); } IInstanceLifeTimeFactory lifeTimeFactory = new InstanceLifeTimeFactory(); types[typeof(TContract)] = lifeTimeFactory.Create(typeof(TImplementation), lsType, null); }
protected override void DoRegister <T>(LifeTimeStyle lifeTimeStyle) { switch (lifeTimeStyle) { case LifeTimeStyle.Singleton: services.AddSingleton <T>(); break; case LifeTimeStyle.Transient: services.AddTransient <T>(); break; case LifeTimeStyle.Scoped: services.AddScoped <T>(); break; } }
protected override void DoRegister(Type type, Type impl, LifeTimeStyle lifeTimeStyle) { switch (lifeTimeStyle) { case LifeTimeStyle.Singleton: services.AddSingleton(type, impl); break; case LifeTimeStyle.Transient: services.AddTransient(type, impl); break; case LifeTimeStyle.Scoped: services.AddScoped(type, impl); break; } }
public IInstanceLifeTime Create(Type t, LifeTimeStyle lt, object o) { switch (lt) { case LifeTimeStyle.Singleton: return(new SingletonLifeTime() { ResolvedType = t, InstanceValue = o }); default: return(new TransientLifeTime() { ResolvedType = t, InstanceValue = null }); } }
public void Register <T>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where T : class { ObjectContainer.Register <T>(lifeTimeStyle); }
public void Register(Type type, Type impl, LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) { ObjectContainer.Register(type, impl, lifeTimeStyle); }
public void Register <TType, TImpl>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where TType : class where TImpl : class, TType { ObjectContainer.Register <TType, TImpl>(lifeTimeStyle); }
public void Register <T>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where T : class { this.DoRegister <T>(lifeTimeStyle); }
protected abstract void DoRegister <T>(LifeTimeStyle lifeTimeStyle) where T : class;
public void Register(Type type, Type impl, LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) { this.DoRegister(type, impl, lifeTimeStyle); }
protected abstract void DoRegister(Type type, Type impl, LifeTimeStyle lifeTimeStyle);
public void Register <TType, TImpl>(LifeTimeStyle lifeTimeStyle = LifeTimeStyle.Singleton) where TType : class where TImpl : class, TType { this.DoRegister <TType, TImpl>(lifeTimeStyle); }
protected abstract void DoRegister <TType, TImpl>(LifeTimeStyle lifeTimeStyle) where TType : class where TImpl : class, TType;