This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Container Support
Jarnpher-Rice edited this page Jul 14, 2017
·
9 revisions
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
existingContainer.Bind<IApplicationSingleton>()
.To<ApplicationSingleton>().InSingletonScope();
//transient binding
existingContainer.Bind<ICommandHandler>().To<CommandHandler>();
}
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.
container.Bind<IPerRequest>().To<PerRequest>().InSingletonScope();
}
}
From stackoverflow
public class Bootstrapper : AutofacNancyBootstrapper
{
protected override void ConfigureApplicationContainer(ILifetimeScope existingContainer)
{
var builder = new ContainerBuilder();
builder.RegisterType<User>()
.As<IUser>()
.SingleInstance();
builder.Update(existingContainer.ComponentRegistry);
}
}
...
- Introduction
- Exploring the Nancy module
- Routing
- Taking a look at the DynamicDictionary
- Async
- View Engines
- Using Models
- Managing static content
- Authentication
- Lifecycle of a Nancy Application
- Bootstrapper
- Adding a custom FavIcon
- Diagnostics
- Generating a custom error page
- Localization
- SSL Behind Proxy
- Testing your application
- The cryptography helpers
- Validation
- Hosting Nancy with ASP.NET
- Hosting Nancy with WCF
- Hosting Nancy with Azure
- Hosting Nancy with Suave.IO
- Hosting Nancy with OWIN
- Hosting Nancy with Umbraco
- Hosting Nancy with Nginx on Ubuntu
- Hosting Nancy with FastCgi
- Self Hosting Nancy
- Implementing a Host
- Accessing the client certificate when using SSL
- Running Nancy on your Raspberry Pi
- Running Nancy with ASP.NET Core 3.1