title: RabbitMQ consumer in ASP.NET Core application whith out the web request
body: <p>Summary i do how it resolved in <a href="https://stackoverflow.com/questions/43609345/setup-rabbitmq-consumer-in-asp-net-core-application/43610530#comment98659771_43610530">Setup RabbitMQ consumer in ASP.NET Core application</a>
  but my Rabbit consumer online if i do web request, if i start IIS and don't start browser request, Rabbit consumer is not started.
  Have any one know why? 
  Can a web application do the work of a web application and a Windows service or  is it a bad idea.</p>
  
  <pre><code>    // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          ...
          services.AddSingleton&lt;RabbitListener&gt;();
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env)
      {
          app.UseRabbitListener();
          ...
      }
  
  }
  public static class ApplicationBuilderExtentions
  {
      //the simplest way to store a single long-living object, just for example.
      private static RabbitListener _listener { get; set; }
  
      public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)
      {
          _listener = app.ApplicationServices.GetService&lt;RabbitListener&gt;();
  
  
          var lifetime = app.ApplicationServices.GetService&lt;IApplicationLifetime&gt;();
  
          lifetime.ApplicationStarted.Register(OnStarted);
  
          //press Ctrl+C to reproduce if your app runs in Kestrel as a console app
          lifetime.ApplicationStopping.Register(OnStopping);
  
          return app;
      }
  
      private static void OnStarted()
      {
          foreach (var o in LogOptions.Options)
              _listener.NewRouteAdd(o.QueueString);
          _listener.Register();
      }
  
      private static void OnStopping()
      {
          _listener.Deregister();
      }
  }
  </code></pre>