public void Register <TInterface, TImplement>(DILifeTime lifeTime, Action <ICtorSelectorExpression <TImplement, TInterface> > ctorInjectorExpression) where TInterface : class where TImplement : class, TInterface { var parameters = new List <object>(); var ctorSelectorExpression = new UCtorSelectorExpression <TImplement, TInterface>(this.container, parameters); ctorInjectorExpression(ctorSelectorExpression); switch (lifeTime) { case DILifeTime.Singleton: this.container.RegisterType <TInterface, TImplement>(new ContainerControlledLifetimeManager(), parameters.Count == 0 ? new InjectionConstructor() : new InjectionConstructor(parameters.ToArray())); break; case DILifeTime.Trasient: this.container.RegisterType <TInterface, TImplement>(new TransientLifetimeManager(), parameters.Count == 0 ? new InjectionConstructor() : new InjectionConstructor(parameters.ToArray())); break; case DILifeTime.Scoped: this.container.RegisterType <TInterface, TImplement>(new PerResolveLifetimeManager(), parameters.Count == 0 ? new InjectionConstructor() : new InjectionConstructor(parameters.ToArray())); break; } }
public void Register <TInterface, TImplement>(string name, DILifeTime lifeTime) where TInterface : class where TImplement : class, TInterface { var register = this.configuration.For <TInterface>().Use <TImplement>().Named(name); SetLifeTime(lifeTime, register); }
internal void Register( InstanceExpression <TInter> @for, ConstructorInstance <TImpl, TInter> use, string instanceName, DILifeTime lifetime, Action <DILifeTime, ConstructorInstance <TImpl, TInter> > setLifeTime) { this.@for = @for; this.use = use; this.instanceName = instanceName; this.lifetime = lifetime; this.setLifeTime = setLifeTime; }
internal void Register( CreatePluginFamilyExpression <TInter> @for, SmartInstance <TImpl, TInter> use, string instanceName, DILifeTime lifetime, Action <DILifeTime, LambdaInstance <TImpl, TInter> > setLifeTime) { this.@for = @for; this.use = use; this.instanceName = instanceName; this.lifetime = lifetime; this.setLifeTime = setLifeTime; }
public void Register <TInterface, TImplement>(DILifeTime lifeTime, Action <ICtorSelectorExpression <TImplement, TInterface> > ctorInjectorExpression) where TInterface : class where TImplement : class, TInterface { var @for = this.configuration.For <TInterface>(); var use = @for.Use <TImplement>(); var ctorSelectorExpression = new SMCtorSelectorExpression <TImplement, TInterface>(); ctorSelectorExpression.Register(@for, use, null, lifeTime, SetLifeTime);//Use, lifeTime, setLifeTime and Name only used for Empty constructors ctorInjectorExpression(ctorSelectorExpression); SetLifeTime(lifeTime, use); }
private static void SetLifeTime <TImplement, TInterface>(DILifeTime lifeTime, ConstructorInstance <TImplement, TInterface> register) where TImplement : class, TInterface { if (lifeTime == DILifeTime.Scoped) { register.Lifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Scoped; } else if (lifeTime == DILifeTime.Singleton) { register.Lifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Singleton; } else if (lifeTime == DILifeTime.Trasient) { register.Lifetime = Microsoft.Extensions.DependencyInjection.ServiceLifetime.Transient; } }
private static void SetLifeTime(DILifeTime lifeTime, ObjectInstance register) { if (lifeTime == DILifeTime.Scoped) { register.Scoped(); } else if (lifeTime == DILifeTime.Singleton) { register.Singleton(); } else if (lifeTime == DILifeTime.Trasient) { register.Transient(); } }
private static void SetLifeTime <TInterface, TImplement>(DILifeTime lifeTime, StructureMap.Pipeline.LambdaInstance <TImplement, TInterface> register) where TImplement : TInterface { if (lifeTime == DILifeTime.Scoped) { register.Transient(); } else if (lifeTime == DILifeTime.Singleton) { register.Singleton(); } else if (lifeTime == DILifeTime.Trasient) { register.AlwaysUnique(); } }
public void Register <TInterface, TImplement>(DILifeTime lifeTime) where TInterface : class where TImplement : class, TInterface { switch (lifeTime) { case DILifeTime.Singleton: this.container.RegisterType <TInterface, TImplement>(new Unity.Lifetime.ContainerControlledLifetimeManager()); break; case DILifeTime.Trasient: this.container.RegisterType <TInterface, TImplement>(new Unity.Lifetime.PerResolveLifetimeManager()); break; case DILifeTime.Scoped: this.container.RegisterType <TInterface, TImplement>(new Unity.Lifetime.PerThreadLifetimeManager()); break; } }
public void Register <TInterface, TImplement>(string name, DILifeTime lifeTime, Action <ICtorSelectorExpression <TImplement, TInterface> > ctorInjectorExpression) where TInterface : class where TImplement : class, TInterface { var register = this.configuration.For <TInterface>(); var use = register.Use <TImplement>(); use.Named(name); var ctorSelectorExpression = new SMCtorSelectorExpression <TImplement, TInterface>(); ctorSelectorExpression.Register(register, use, name, lifeTime, SetLifeTime);//Use, lifeTime, setLifeTime and Name only used for Empty constructors ctorInjectorExpression(ctorSelectorExpression); register.Use(() => Activator.CreateInstance <TImplement>()); SetLifeTime(lifeTime, use); }
public Dependency(Type t, DILifeTime lifeTime) { Type = t; DILifeTime = lifeTime; }