forked from NancyFx/Nancy
-
Notifications
You must be signed in to change notification settings - Fork 0
Container Support
Matt Murphy edited this page May 6, 2013
·
6 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();
}
}
...
- Async
- Taking a look at the DynamicDictionary
- The before and after module hooks
- The Application Before, After and OnError pipelines
- Model binding
- Bootstrapper
- View Engines
- View location conventions
- Localization
- Testing your application
- The root path
- Managing static content
- Diagnostics
- Adding a custom FavIcon
- Generating a custom error page
- The cryptography helpers
- Content negotiation
- Authentication
- More to come