-
Notifications
You must be signed in to change notification settings - Fork 40
Setting up a OWIN WebApi application
This chapter explains a new feature coming with the next release. It is not supported by the current release.
This chapter explains how to setup an application in case you want to use the OWIN (Open Web Interface for .NET) interface to be able to move your application between OWIN supporting hosts without making code changes.
First you have to add a reference to Ninject.Web.Common.OwinHost either by adding the reference manually or installing the corresponding NuGet Package. Then you can initialize the Ninject middleware with the extension method UseNinjectMiddleware and register the WebApi through Ninject with the extension method UseNinjectWebApi. To start the WebApi you have to pass a Configuration. This configuration is specific to the WebApi technology. Please read the documentation for this technologies to get more informations about how to configure a service.
````text public void Configuration(IAppBuilder app)
{
var webApiConfiguration = new HttpConfiguration();
webApiConfiguration.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional, controller = "values" });
app.UseNinjectMiddleware(CreateKernel).UseNinjectWebApi(webApiConfiguration);
}
private static StandardKernel CreateKernel() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); return kernel; }