using SimpleInjector; using SimpleInjector.Integration.WebApi; using System.Web.Http; public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { // Create the container var container = new Container(); // Register all Web API controllers container.RegisterWebApiControllers(GlobalConfiguration.Configuration); // Register other dependencies // Verify the container configuration is correct container.Verify(); // Replace the default Web API dependency resolver with Simple Injector GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); // Start the Web API configuration GlobalConfiguration.Configure(WebApiConfig.Register); } }
using SimpleInjector; using SimpleInjector.Integration.WebApi; using System.Web.Http; public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { // Create the container var container = new Container(); // Register a specific Web API controller container.RegisterBoth examples use the SimpleInjector and SimpleInjector.Integration.WebApi packages to register and inject dependencies for Web API controllers.(); // Register all Web API controllers container.RegisterWebApiControllers(GlobalConfiguration.Configuration); // Register other dependencies // Verify the container configuration is correct container.Verify(); // Replace the default Web API dependency resolver with Simple Injector GlobalConfiguration.Configuration.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container); // Start the Web API configuration GlobalConfiguration.Configure(WebApiConfig.Register); } }