private static ILifetime ResolveLifetime(ServiceDescriptor serviceDescriptor)
        {
            if (serviceDescriptor.ImplementationInstance != null)
            {
                return(null);
            }

            ILifetime lifetime = null;

            switch (serviceDescriptor.Lifetime)
            {
            case ServiceLifetime.Scoped:
                lifetime = new PerScopeLifetime();
                break;

            case ServiceLifetime.Singleton:
                lifetime = new PerContainerLifetime();
                break;

            case ServiceLifetime.Transient:
                lifetime = new PerRequestLifeTime();
                break;
            }

            return(lifetime);
        }
        public void Registration(IEnumerable <RegistrationDefinition> definitions)
        {
            foreach (var definition in definitions)
            {
                ILifetime lifetime = null;

                switch (definition.RegistrationLifestyle)
                {
                case RegistrationLifestyle.Singleton:
                    lifetime = new PerContainerLifetime();
                    break;

                case RegistrationLifestyle.SingletonPerScope:
                    lifetime = new PerScopeLifetime();
                    break;
                }

                if (definition.RegistrationMode == RegistrationMode.Single)
                {
                    _container.Register(definition.ExportType, definition.ActivationType, lifetime);
                }
                else
                {
                    _container.Register(definition.ExportType, definition.ActivationType, definition.ActivationType.Name, lifetime);
                }
            }
        }
Ejemplo n.º 3
0
        public void ShouldClonePerContainerLifetime()
        {
            var lifetime = new PerContainerLifetime();

            var clone = lifetime.Clone();

            Assert.IsType <PerContainerLifetime>(clone);
        }
Ejemplo n.º 4
0
        private static void RegisterBindings(ServiceContainer serviceContainer, Type bindToType, IEnumerable <Type> bindFromTypes, ServiceBindingOptionsAttribute?options)
        {
            string serviceName = bindToType.GetInternalServiceName();

            PerContainerLifetime lifeTime = new PerContainerLifetime();

            RegisterExplicitBindings(serviceContainer, bindToType, bindFromTypes, serviceName, lifeTime);

            if (options is not {
                Lazy : true
            })