All kernels register on the static list of this class. This allows derived types to do things for the kernels. e.g. used by One per request module to release the objects in request scope right after the request ended.
Inheritance: Ninject.Infrastructure.Disposal.DisposableObject
Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }