title: OWIN Startup class is being executed along with WebAPIConfig.Register method
body: <p>I am using <code>Microsoft.Owin.Hosting</code> in my one of integration test project to self-host the Web API in order to test end to end functionality.</p>
  
  <pre><code>[TestMethod]
  public void GetLoanApplications()
  {
      using (WebApp.Start&lt;Startup&gt;(url: url))
      {
          using (var client = new HttpClient())
          {
              // Create httpclient and send request-and-response-metadata-in-aspnet-web-api
          }
      }
  }
  </code></pre>
  
  <p>I am able to self-host the web API and able to invoke the controller action. Owin requires some <code>Startup</code> class configuration, which is as follows:</p>
  
  <pre><code>[assembly: OwinStartup(typeof(MyService.App_Start.Startup))]
  namespace MyService.App_Start
  {
      public class Startup
      {
          public void Configuration(IAppBuilder app)
          {
              HttpConfiguration config = new HttpConfiguration();
              config.MapHttpAttributeRoutes();
  
              config.Routes.MapHttpRoute(
                  name: "DefaultApi",
                  routeTemplate: "api/{controller}/{id}",
                  defaults: new { id = RouteParameter.Optional }
              );
              app.UseWebApi(config);
          }
      }
  }
  </code></pre>
  
  <p>Here is my Web API Config method looks like:</p>
  
  <pre><code>public class WebApiApplication : System.Web.HttpApplication
  {
      protected void Application_Start()
      {
          GlobalConfiguration.Configure(WebApiConfig.Register);
      }
  }
  
  public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          config.MapHttpAttributeRoutes();
  
          config.Routes.MapHttpRoute(
              name: "DefaultApi",
              routeTemplate: "api/{controller}/{id}",
              defaults: new { id = RouteParameter.Optional }
          );            
      }
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <ul>
  <li>When I run my main application (not the test project) both the Owin startup and web API config methods are getting called.</li>
  <li>Let's say if I have some services or filters to be configured, it will get invoked twice.</li>
  <li>What I thought is IF I am running test project it should only invoke owin startup file (<strong>which it is doing right now</strong>) and when I am debugging my main app it should only call web API config register method.</li>
  </ul>
  
  <p>Any idea on is this the way it should work or I am doing something wrong?</p>