title: How do I inject NavigationManager in a Quartz.NET job?
body: <p>I have a Blazor server-side application that uses Quartz.NET to run a scheduled job. The job merely calls an injected helper class...</p>
  <pre class="lang-cs prettyprint-override"><code>  public class DownloadEmailsJob : IJob {
      private readonly EmailDownloadHelper _edh;
  
      public DownloadEmailsJob(EmailDownloadHelper edh) =&gt;
        _edh = edh;
  
      public async Task Execute(IJobExecutionContext context) =&gt;
        await _edh.DownloadEmails();
    }
  </code></pre>
  <p><code>EmailDownloadHelper</code> uses injection to get various services, such as the <code>DbContext</code>, etc. That part is all working fine.</p>
  <p>I now have a need to call a SignalR hub method from inside the helper class. Following the code <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr-blazor?view=aspnetcore-5.0&amp;tabs=visual-studio&amp;pivots=server" rel="nofollow noreferrer">in Microsoft's documentation</a>, in order to create the hub connection, I need to do something like this...</p>
  <pre class="lang-cs prettyprint-override"><code>_hubConnection = new HubConnectionBuilder()
    .WithUrl(_navigationManager.ToAbsoluteUri(EmailNotifierHub.Endpoint))
    .Build();
  </code></pre>
  <p>...where <code>EmailNotifierHub</code> contains the following line...</p>
  <pre class="lang-cs prettyprint-override"><code>public const string Endpoint = &quot;/EmailHub&quot;;
  </code></pre>
  <p>This means that I need an instance of <code>NavigationManager</code> in my job. I tried injecting it in the constructor (as I do with the other dependencies in this class), but when it tries to create the hub connection, I get an exception...</p>
  <blockquote>
  <p>System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll
  'RemoteNavigationManager' has not been initialized</p>
  </blockquote>
  <p>The instance of <code>NavigationManager</code> is injected fine, meaning it's not null, and the exception only comes when it tries to call <code>ToAbsoluteUri</code></p>
  <p>I've done this sort of thing before in injected classes, but not in a Quartz.NET job, which is where I suspect the problem lies.</p>
  <p>Anyone able to explain what's going wrong, and how I fix it? Thanks</p>