/// <summary> /// Initializes a new instance of the <see cref="KernelBase"/> class. /// </summary> /// <param name="components">The component container to use.</param> /// <param name="settings">The configuration to use.</param> /// <param name="modules">The modules to load into the kernel.</param> protected KernelBase(IComponentContainer components, INinjectSettings settings, params INinjectModule[] modules) { Ensure.ArgumentNotNull(components, "components"); Ensure.ArgumentNotNull(settings, "settings"); Ensure.ArgumentNotNull(modules, "modules"); this.Settings = settings; this.Components = components; components.Kernel = this; this.AddComponents(); GlobalKernelRegistry.StartManaging(this); #if !NO_ASSEMBLY_SCANNING if (this.Settings.LoadExtensions) { this.Load(this.Settings.ExtensionSearchPatterns); } #endif this.Bind <IKernel>().ToConstant(this).InTransientScope(); this.Bind <IResolutionRoot>().ToConstant(this).InTransientScope(); this.Load(modules); }
/// <summary> /// Releases resources held by the object. /// </summary> public override void Dispose(bool disposing) { if (disposing && !IsDisposed) { GlobalKernelRegistry.StopManaging(this); if (this.Components != null) { // Deactivate all cached instances before shutting down the kernel. var cache = this.Components.Get <ICache>(); cache.Clear(); this.Components.Dispose(); } } base.Dispose(disposing); }