title: services.AddSingleton, service's constructor is never called
body: <p>tl;dr</p>
  
  <pre><code>services.AddSingleton&lt;ISomeService, SomeService&gt;();
  // SomeService not instantiated nor initialized?
  </code></pre>
  
  <p>In a variation on the classic SignalR Chat app, I'm monitoring changes to a SQL Server table and reporting them in real-time through SignalR. Watch <a href="https://youtu.be/JBhVpfb1LhU?t=90" rel="noreferrer">this video</a> for 10 seconds to get the idea. My code is adapted from <a href="https://github.com/gavilanch/SignalR_Core_Ejemplo" rel="noreferrer">this project</a>. The chat part works fine.</p>
  
  <p>Changes to the SQL Server table are supposed to be monitored by class <code>SqlDependencyService</code>. However, <strong>its constructor is never called</strong>, and that's where it should get a reference to the SignalR hub.</p>
  
  <p>Here's my Startup.ConfigureServices:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
          options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
      services.AddSignalR();
  
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
  
      // No instantiation ?!?
      services.AddSingleton&lt;IDatabaseChangeNotificationService, SqlDependencyService&gt;();
  
      // My lame attempt at forcing instantiation:
      SqlDependencyService sqlDS = serviceProvider.GetService&lt;SqlDependencyService&gt;();
      //sqlDS.Config(); // Fails, sqlDS is null.
  }
  </code></pre>
  
  <p>And here's part of my SqlDependencyService class:</p>
  
  <pre><code>public class SqlDependencyService : IDatabaseChangeNotificationService
      {
          private readonly IConfiguration configuration;
          private readonly IHubContext&lt;ChatHub&gt; chatHub;
  
          // Never gets called!        
          public SqlDependencyService(IConfiguration configuration, IHubContext&lt;ChatHub&gt; chatHub)
          {
              this.configuration = configuration;
              this.chatHub = chatHub;
          }
  
          // Never gets called!    
          public void Config()
          {
              SubscribeToPersonTableChanges();
          }
  
          private void SubscribeToPersonTableChanges()
          {
              // ...
          }
  
          // ...
      }
  </code></pre>
  
  <p>Here's the service's interface:</p>
  
  <pre><code>public interface IDatabaseChangeNotificationService
  {
      void Config();
  }
  </code></pre>
  
  <p>As stated, the constructor is never called. Additionally, I don't see how the Config method could possibly be invoked - some ASP.NET Core convention magic?</p>
  
  <p>I don't have this issue with the HomeController, whose constructor is called and passed an <code>IHubContext&lt;ChatHub&gt;</code>:</p>
  
  <pre><code>public class HomeController : Controller
  {
      private readonly IHubContext&lt;ChatHub&gt; chatHub;
  
      public HomeController(IHubContext&lt;ChatHub&gt; chatHub)
      {
          this.chatHub = chatHub;
      }
  
      // ...
  }
  </code></pre>