title: What is an correct way to inject db context to Hangfire Recurring job?
body: <p>I'm using HangFire to send emails to users in the background, regularly.</p>
  
  <p>I'm obtaining email addresses from database, but I'm not sure whether I'm "injecting" database context to service that's responsible for sending emails correctly</p>
  
  <p>This works correctly, is there a better way to do it?</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, Context context)
  {
      (...)
  
      app.UseHangfireDashboard();
      app.UseHangfireServer(new BackgroundJobServerOptions
      {
          HeartbeatInterval = new System.TimeSpan(0, 0, 5),
          ServerCheckInterval = new System.TimeSpan(0, 0, 5),
          SchedulePollingInterval = new System.TimeSpan(0, 0, 5)
      });
  
      RecurringJob.AddOrUpdate(() =&gt; new MessageService(context).Send(), Cron.Daily);
  
      (...)
      app.UseMvc();
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class MessageService
  {
      private Context ctx;
  
      public MessageService(Context c)
      {
          ctx = c;
      }
  
      public void Send()
      {
          var emails = ctx.Users.Select(x =&gt; x.Email).ToList();
  
          foreach (var email in emails)
          {
              sendEmail(email, "sample body");
          }
      }
  }
  </code></pre>