Skip to content
This repository was archived by the owner on Apr 26, 2020. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Nancy.Bootstrappers.Ninject/NinjectNancyBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nancy.Bootstrapper;
using global::Ninject;
using global::Ninject.Extensions.ChildKernel;
using global::Ninject.Infrastructure;

/// <summary>
/// Nancy bootstrapper for the Ninject container.
Expand Down Expand Up @@ -128,9 +129,9 @@ protected override void RegisterInstances(IKernel container, IEnumerable<Instanc
/// Creates a per request child/nested container
/// </summary>
/// <returns>Request container instance</returns>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of the scope of setting the scope as Singleton by default? =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, in most cases, it is Singleton in request scope. Since CreateRequestContainer is marked as sealed, I can't set the kernel's default scope. That's why I sent this pull request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was remaking why do you nee to unseal it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't understand your question. Are you asking why I unseal the method? Just as I said, otherwise I can't set NinjectSettings for the ChildKernel.
For example, I want to set AllowNullInjection to true.
The NinjectSettings can only pass by kernel's constructor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so you unsealed it, so you can override it in your own boostrapper like

public class MyBootstrapper : NinjectNancyBootstrapper
{
    public override IKernel CreateRequestContainer()
    {
         // create your IKernel instance and return it;
    }
}

??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you got it

protected override sealed IKernel CreateRequestContainer()
protected override IKernel CreateRequestContainer()
{
return new ChildKernel(this.ApplicationContainer);
return new ChildKernel(this.ApplicationContainer, new NinjectSettings { DefaultScopeCallback = StandardScopeCallbacks.Singleton });
}

/// <summary>
Expand All @@ -144,7 +145,7 @@ protected override sealed IEnumerable<INancyModule> GetAllModules(IKernel contai
}

/// <summary>
/// Retreive a specific module instance from the container
/// Retrieve a specific module instance from the container
/// </summary>
/// <param name="container">Container to use</param>
/// <param name="moduleType">Type of the module</param>
Expand Down