title: How to use DI in this example?
body: <p>I followed this example <a href="https://docs.microsoft.com/pt-br/azure/app-service/webjobs-sdk-get-started" rel="nofollow noreferrer">https://docs.microsoft.com/pt-br/azure/app-service/webjobs-sdk-get-started</a> and it is working fine. What I want to do is to make the connection strings (strongly typed) available in all methods within Functions class. My Connection Strings object:</p>
  
  <pre><code>namespace MyApp.Domain
  {
    public class Secrets
    {
      public class ConnectionStrings
      {
        public string SqlServer {get; set;}
        public string Storage {get; set;}
        public string SendGrid {get; set;}
        public string AzureWebJobsDashboard { get; set; }
        public string AzureWebJobsStorage {get; set;}
      }
    }
  }
  </code></pre>
  
  <p>In web project I use (and it works perfectly):</p>
  
  <pre><code>services.Configure&lt;Secrets.ConnectionStrings&gt;(Configuration.GetSection("CUSTOMCONNSTR_ConnectionStrings"));
  </code></pre>
  
  <p>and in the classes' constructors I use:</p>
  
  <pre><code>public class EmailController: ControllerBase
    {
      private readonly MyEmail _myEmail;
  
      public EmailController(MyEmail MyEmail)
      {
        _myEmail = MyEmail;
      }
  
      [HttpGet]
      public async Task&lt;ActionResult&lt;string&gt;&gt; SendEmail()
      {
        try
        {
          ...
  
          return await _myEmail.SendMailMI3D(myMsg);
        }
        catch (System.Exception ex)
        {
            return ex.Message + " - " + ex.StackTrace;
        }
      }
  
      [HttpGet("sendgrid")]
      public string GetSendGrid(long id)
      {
        return _myEmail.SendGridConnStr();
      }
    }
  </code></pre>
  
  <p>But this way doesn't work on webjobs (console apps).</p>
  
  <p>I tried to insert a simple Console.WriteLine in Functions' constructor but it doesn't work as well. So I think this is the problem: Functions' constructor is not being called. So when I insert a message in my queue I receive this error message related to DI Connection String:</p>
  
  <p>Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage ---> System.NullReferenceException: Object reference not set to an instance of an object.</p>
  
  <p>Can anybody please help me? Thanks a lot.</p>
  
  <pre><code>public Functions(IOptions&lt;Secrets.ConnectionStrings&gt; ConnectionStrings)
      {
        _connectionStrings = ConnectionStrings;
  
        Console.WriteLine("Simple line");
        Console.WriteLine($"Functions constructor: ${_connectionStrings.Value.SendGrid}");
      }
  </code></pre>
  
  <p>Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ProcessQueueMessage ---> System.NullReferenceException: Object reference not set to an instance of an object.</p>