/*----------------------------------------------------------------------------------------*/ /// <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(); } }
/*----------------------------------------------------------------------------------------*/ #region Protected Methods /// <summary> /// Connects a component to the kernel. /// </summary> /// <param name="type">The service that the component provides.</param> /// <param name="component">The instance of the component.</param> protected override void DoConnect(Type type, IKernelComponent component) { Ensure.ArgumentNotNull(type, "type"); Ensure.ArgumentNotNull(component, "member"); Ensure.NotDisposed(this); lock (_components) { // Remove the component if it's already been connected. if (_components.ContainsKey(type)) { DoDisconnect(type); } component.Connect(Kernel); _components.Add(type, component); } }
/*----------------------------------------------------------------------------------------*/ #region Protected Methods /// <summary> /// Connects a component to the kernel. /// </summary> /// <param name="type">The service that the component provides.</param> /// <param name="component">The instance of the component.</param> protected override void DoConnect(Type type, IKernelComponent component) { Ensure.ArgumentNotNull(type, "type"); Ensure.ArgumentNotNull(component, "member"); Ensure.NotDisposed(this); lock (_components) { // Remove the component if it's already been connected. if (_components.ContainsKey(type)) DoDisconnect(type); component.Connect(Kernel); _components.Add(type, component); } }
/*----------------------------------------------------------------------------------------*/ #region Protected Methods /// <summary> /// Connects a component to the kernel. /// </summary> /// <param name="type">The service that the component provides.</param> /// <param name="component">The instance of the component.</param> protected abstract void DoConnect(Type type, IKernelComponent component);
/*----------------------------------------------------------------------------------------*/ /// <summary> /// Connects a component to the kernel. If a component with the specified service is /// already connected, it will be disconnected first. /// </summary> /// <param name="type">The service that the component provides.</param> /// <param name="component">The instance of the component.</param> public void Connect(Type type, IKernelComponent component) { DoConnect(type, component); }
/*----------------------------------------------------------------------------------------*/ IBindingHeuristicComponentOrParameterSyntax IBindingComponentSyntax.WithComponent(Type type, IKernelComponent component) { Binding.Components.Connect(type, component); return(this); }