title: Setup hangfire jobs correctly within an ASPNET Core 2.1 application?
body: <p>Moving to asp.net core 2.1 is breaking our hangfire job setup.</p>
  
  <p>In the <code>Main</code> method of <code>Program.cs</code> we have something like</p>
  
  <pre><code>var webHost = BuildWebHost(args);
  ConfigureHangfireJobs(webHost);
  webHost.Run();
  </code></pre>
  
  <p>The <code>BuildWebHost</code> looks like this:</p>
  
  <pre><code>return WebHost.CreateDefaultBuilder(args)
      .ConfigureAppConfiguration(ConfigConfiguration)
      .UseStartup&lt;Startup&gt;()
      .UseApplicationInsights()
      .Build();
  </code></pre>
  
  <p><code>ConfigureHangfireJobs</code> is calling <code>RecurringJob.AddOrUpdate()</code> which needs the <code>JobStorage.Current</code> to be set, and I found it gets set when the hangfireserver middleware is added, while the hangfire service is configured in the <code>Startup.ConfigureServices</code> method. As far as I know, middleware setup is to be done in the <code>Configure</code> method of the <code>Startup</code> class, so that's where we call the <code>app.UseHangfireServer</code> which sets the <code>JobStorage.Current</code>.</p>
  
  <p>With core 2.0 everything was running fine as the <code>Configure</code> method was called during our <code>BuildWebHost()</code> method and so the <code>JobStorage.Current</code> was then setup and available for the <code>ConfigureHangfireJobs</code>. But when switching to core 2.1, the <code>Configure</code> is now called as part of the <code>webHost.Run()</code> method. Which means our <code>ConfigureHangfireJobs</code> now fails because the <code>JobStorage.Current</code> is not ready yet.</p>
  
  <p>Now, of course I could setup the hangfire jobs as part of the <code>Startup.Configure</code> method, but that's just not where it belongs. An other option would be to setup the <code>JobStorage.Current</code> myself, but then isn't that the responsibility of the hangfireserver middleware ?</p>
  
  <p>So my question is: how are we supposed to setup hangfire jobs correctly in core 2.1 ?</p>