public void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { switch (lifetime) { case AbstractLifetime.Transient: if (!_collections.TryGetValue(contractType, out var implementations)) { implementations = new List <Type> { implementationType }; _collections.Add(contractType, implementations); _container.Register(contractType, implementationType); } else { implementations.Add(contractType); } break; case AbstractLifetime.Singleton: _container.RegisterSingleton(contractType, implementationType); break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } }
public override void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { switch (lifetime) { case AbstractLifetime.Transient: if (name.IsNullOrEmpty()) { _container.Register(contractType, implementationType); } else { _container.Register(contractType, implementationType, name); } break; case AbstractLifetime.Singleton: if (name.IsNullOrEmpty()) { _container.Register(contractType, implementationType, new PerContainerLifetime()); } else { _container.Register(contractType, implementationType, name, new PerContainerLifetime()); } break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } }
public override void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { var registration = Component.For(contractType).ImplementedBy(implementationType); switch (lifetime) { case AbstractLifetime.Transient: registration.LifestyleTransient(); break; case AbstractLifetime.Singleton: registration.LifestyleSingleton(); break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } if (name != null) { registration.Named(name); } _container.Register(registration); }
public void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { ITypeLifetimeManager lifetimeManager = null; switch (lifetime) { case AbstractLifetime.Transient: break; case AbstractLifetime.Singleton: lifetimeManager = new ContainerControlledLifetimeManager(); break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } ((IUnityContainer)_container).RegisterType(contractType, implementationType, name, lifetimeManager); }
public void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { IReuse reuse; switch (lifetime) { case AbstractLifetime.Transient: reuse = Reuse.Transient; break; case AbstractLifetime.Singleton: reuse = Reuse.Singleton; break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } _container.Register(new ReflectionFactory(implementationType, reuse), contractType, name, null, true); }
public void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { var bind = _container.Bind(contractType).To(implementationType); switch (lifetime) { case AbstractLifetime.Transient: break; case AbstractLifetime.Singleton: bind.InSingletonScope(); break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } if (name != null) { bind.Named(name); } }
public override void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) { var bind = _container.Bind(contractType); switch (lifetime) { case AbstractLifetime.Transient: break; case AbstractLifetime.Singleton: bind = bind.Lifetime(new SingletonLifetime(false)); break; default: throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null); } if (name != null) { bind = bind.Tag(name); } bind.To(implementationType); }
public override void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) => _container.Register(contractType, implementationType, lifetime, name);