Skip to content

Container Support

Slava edited this page Mar 9, 2015 · 8 revisions
Clone this wiki locally


First, install the Nancy.Bootstrappers.Ninject package. Then, make your custom bootstrapper inherit from NinjectNancyBootstrapper instead of DefaultNancyBootstrapper. Finally, override the ConfigureApplicationContainer and the ConfigureRequestContainer methods, and bind your dependencies. The container parameter in ConfigureRequestContainer is a child container which is disposed at the end of the request.

public class Bootstrapper : NinjectNancyBootstrapper
    protected override void ConfigureApplicationContainer(IKernel existingContainer)
        //application singleton
        //transient binding

    protected override void ConfigureRequestContainer(IKernel container, NancyContext context)
        //container here is a child container. I.e. singletons here are in request scope.
        //IDisposables will get disposed at the end of the request when the child container does.


From stackoverflow

public class Bootstrapper : AutofacNancyBootstrapper
    protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
        var builder = new ContainerBuilder();


More to come


Something went wrong with that request. Please try again.