i'm wondering whether it is possible to use multiple kernels in one
application where one kernel object could inherit all bindings from
another? I have a componented oriented software where there are many
different componentes that are composed in a large tree. With NInject
i can isolate the creation and configuration of those, but i seems
this is only possible within the whole application scope. What i
really want is the possibility to create kernels out of existing ones
like this:
var derivedKernel = new StandardKernel(existingKernel, myNewModules);
The existing kernel remains untouched, but the new one inherits all
modules plus a few new ones that can also override old bindings.
This allows me to re-configure the bindings within a component. The
new kernel will be passed to the child-components, where it will be
used to instantiate any IIComponent component - depending on the
position within the large component tree.
Any ideas on how to achieve this with NInect?
georg
--
You received this message because you are subscribed to the Google Groups "ninject" group.
To post to this group, send email to nin...@googlegroups.com.
To unsubscribe from this group, send email to ninject+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ninject?hl=en.
Might this help?
public class ChildKernel : StandardKernel
{
private readonly IResolutionRoot parent;
/// <summary>
/// Initializes a new instance of the <see cref="ChildKernel"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="modules">The modules.</param>
public ChildKernel(IResolutionRoot parent, params INinjectModule[] modules)
: base(modules)
{
this.parent = parent;
}
/// <summary>
/// Initializes a new instance of the <see cref="ChildKernel"/> class.
/// </summary>
/// <param name="parent">The parent.</param>
/// <param name="settings">The settings.</param>
/// <param name="modules">The modules.</param>
public ChildKernel(IResolutionRoot parent, INinjectSettings settings, params INinjectModule[] modules)
: base(settings, modules)
{
this.parent = parent;
}
/// <summary>
/// Determines whether the specified request can be resolved.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>
/// <c>True</c> if the request can be resolved; otherwise, <c>false</c>.
/// </returns>
public override bool CanResolve(IRequest request)
{
return base.CanResolve(request) || this.parent.CanResolve(request);
}
/// <summary>
/// Resolves instances for the specified request. The instances are not actually resolved
/// until a consumer iterates over the enumerator.
/// </summary>
/// <param name="request">The request to resolve.</param>
/// <returns>
/// An enumerator of instances that match the request.
/// </returns>
public override IEnumerable<object> Resolve(IRequest request)
{
return base.CanResolve(request) ? base.Resolve(request) : this.parent.Resolve(request);
and they'll be deactivated here.