Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
 public override void Register(Type contractType, Type implementationType, AbstractLifetime lifetime, string name) =>
 _container.Register(contractType, implementationType, lifetime, name);