-
Notifications
You must be signed in to change notification settings - Fork 529
Extending Ninject
The internals of Ninject are broken up into components that are wired together using a lightweight Inversion of Control container (yes, Ninject is actually two Dependency Injection frameworks). This allows custom behavior to be inserted into the resolution pipeline. The components that Ninject use are all accessed from the Components property off of IKernel
. These components are generally loaded from a subclass of KernelBase
such as StandardKernel
but can also be added externally. For more information see Component Extension Points.
The coordinator of all these components is KernelBase
and you can further modify Ninject’s behavior by tapping into the KernelBase extension points.
To modify which components are in use by Ninject you can access the Components
collection directly to add or remove components.
var kernel = new Kernelbase(); kernel.Components.Add<IMissingBindingResolver, MyMissingBindingResolver>();
You can also derive a class from KernelBase
or StandardKernel
and implement the AddComponents
method. In fact, StandardKernel
is merely a thin wrapper around KernelBase
that adds a default set of components. This is StandardKernel.AddComponents()
as it exists in version 2.2:
Components.Add<IPlanner, Planner>(); Components.Add<IPlanningStrategy, ConstructorReflectionStrategy>(); Components.Add<IPlanningStrategy, PropertyReflectionStrategy>(); Components.Add<IPlanningStrategy, MethodReflectionStrategy>(); Components.Add<ISelector, Selector>(); Components.Add<IConstructorScorer, StandardConstructorScorer>(); Components.Add<IInjectionHeuristic, StandardInjectionHeuristic>(); Components.Add<IPipeline, Pipeline>(); Components.Add<IActivationStrategy, ActivationCacheStrategy>(); Components.Add<IActivationStrategy, PropertyInjectionStrategy>(); Components.Add<IActivationStrategy, MethodInjectionStrategy>(); Components.Add<IActivationStrategy, InitializableStrategy>(); Components.Add<IActivationStrategy, StartableStrategy>(); Components.Add<IActivationStrategy, BindingActionStrategy>(); Components.Add<IActivationStrategy, DisposableStrategy>(); Components.Add<IBindingResolver, StandardBindingResolver>(); Components.Add<IBindingResolver, OpenGenericBindingResolver>(); Components.Add<IMissingBindingResolver, DefaultValueBindingResolver>(); Components.Add<IMissingBindingResolver, SelfBindingResolver>(); #if !NO_LCG if (!Settings.UseReflectionBasedInjection) { Components.Add<IInjectorFactory, DynamicMethodInjectorFactory>(); } else #endif { Components.Add<IInjectorFactory, ReflectionInjectorFactory>(); } Components.Add<ICache, Cache>(); Components.Add<IActivationCache, ActivationCache>(); Components.Add<ICachePruner, GarbageCollectionCachePruner>(); #if !NO_ASSEMBLY_SCANNING Components.Add<IModuleLoader, ModuleLoader>(); Components.Add<IModuleLoaderPlugin, CompiledModuleLoaderPlugin>(); #endif
Licensed under Apache 2 License
Contents
- Home
- Why Use Ninject
- Getting Started
- Dependency Injection By Hand
- Dependency Injection With Ninject
- Injection Patterns
- Multi Injection
- Object Scopes
- Modules and the Kernel
- Providers, Factory Methods and the Activation Context
- The Activation Process
- How Injection Works
- Contextual Binding
- Conventions-Based Binding