Ejemplo n.º 1
0
        internal object GetScopedService(ServiceRegistration registration, DependencyChain chain)
        {
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(IContainerScope));
            }

            // Attempt to retrieve the instance from the service context.
            var instance = _scopeContext.GetService(registration.ConcreteType);

            // If instance doesn't exist, we need to activate it.
            if (instance == null)
            {
                // Use instance on registration, if defined.
                // Otherwise, activate a new instance.
                instance = registration.ServiceInstance ??
                           _backend.ActivateInstance(registration, chain, new ServiceVisitor(_runtime, this));

                _scopeContext.AddService(registration.ConcreteType, instance);
            }

            return(instance);
        }