title: Cannot call Injected [through dependency injection] object method
body: <p>I am trying to call the SendQueuedEmailsToRecipients method from a Maintenance class. My understanding is that because the Maintenance class depends on the SendQueuedEmailsToRecipients method (which is in a different namespace) then I need to DI the method into the Maintenance class. Is this correct? - I am having trouble doing this.</p>
  <p>I am unsure if I am going about this the right way. (Still learning Csharp and ASP.NET core).  I do not really know where to call up IBulkEmailQueue.  Sorry- I am a bit lost here but am trying to understand.</p>
  <p>My code is:
  root/BLL/MaintenanceBLL/Maintenance.cs</p>
  <pre><code>public class Maintenance : IMaintenance
  {
      private readonly ApplicationDbContext _context;
  
      public Maintenance(ApplicationDbContext Context)
      {
          _context = Context;
      }
      //-------------------**MY DI ATTEMPT**
      private readonly BulkEmailQueue _bulkEmailQueue;
  
      public Maintenance(BulkEmailQueue BulkEmailQueue)
      {
          _bulkEmailQueue = BulkEmailQueue;
      }
      //-------------
      public void DoMaintenance()
      {
          //Parse Maintenance table and action those items
          //where Active=True and ActionDate has pass
          //==================================
          //Retrieve list of rows in Maintenance table
          var maintenances = _context.Maintenance;
          foreach (Models.Maintenance m in maintenances)
          {
              switch (m.Subject)
              {
                  case &quot;Send Queued Emails&quot;:
                      if (m.ActionDateTime &lt;= DateTime.Now)
                      {
                          //BulkEmailQueue bulkEmailQueue = new BulkEmailQueue();//Create new instance 
                          //BulkEmailQueue.SendQueuedEmailsToRecipients();
  
                          _bulkEmailQueue.SendQueuedEmailsToRecipients();  **ERROR DISPLAYS ON THIS LINE**. System.NullReferenceException: 'Object reference not set to an instance of an object.'
  
                          m.ActionDateTime = DateTime.Now.AddMinutes(15);
                          m.LastActionDateTime = DateTime.Now;
                      }
                      break;
                  default:
                      // code block
                      break;
              }
          }
  </code></pre>
  <p>My root/startup contains:</p>
  <pre><code>       services.AddTransient&lt;IMaintenance, Maintenance&gt;();
         services.AddTransient&lt;IBulkEmailQueue, BulkEmailQueue&gt;();
  </code></pre>
  <p>My root/Services/IBulkEmailQueue.cs contains</p>
  <pre><code>    public interface IBulkEmailQueue
       {
         public void SendQueuedEmailsToRecipients();
         public void DeleteRecord();
         public void AddToQueue();
      }
  </code></pre>