Beispiel #1
0
        /*----------------------------------------------------------------------------------------*/
        /// <summary>
        /// Disconnects a component from the kernel.
        /// </summary>
        /// <param name="type">The service that the component provides.</param>
        protected override void DoDisconnect(Type type)
        {
            Ensure.NotDisposed(this);

            lock (_components)
            {
                if (!_components.ContainsKey(type))
                {
                    throw new InvalidOperationException(ExceptionFormatter.KernelHasNoSuchComponent(type));
                }

                IKernelComponent component = _components[type];
                _components.Remove(type);

                component.Disconnect();
                component.Dispose();
            }
        }
Beispiel #2
0
        /*----------------------------------------------------------------------------------------*/
        /// <summary>
        /// Retrieves a component from the kernel.
        /// </summary>
        /// <param name="type">The service that the component provides.</param>
        /// <returns>The instance of the component.</returns>
        protected override IKernelComponent DoGet(Type type)
        {
            Ensure.NotDisposed(this);

            lock (_components)
            {
                IKernelComponent component;

                if (_components.TryGetValue(type, out component))
                {
                    return(component);
                }

                if (ParentContainer != null)
                {
                    return(ParentContainer.Get(type));
                }

                throw new InvalidOperationException(ExceptionFormatter.KernelHasNoSuchComponent(type));
            }
        }