title: Dependency injection injecting null when missing registration in Azure functions
body: <p>I'm getting <code>null</code> injected into my constructor that has a dependency which I forgot to register. </p>
  
  <p>In the below example dependency would be <code>null</code> when you forget to register <code>IDepencency</code> in the startup class</p>
  
  <pre><code>public class AzureFunction {
      public AzureFunction(IDepencency dependency) {
  
      }
  }
  </code></pre>
  
  <p>I expected it to work the same as in .net core DI.</p>
  
  <p>Is this expected behavior? And can I maybe change a setting to enable throwing exceptions? </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>After reading HariHaran's answer, I realized it's only happening in a sub-dependency. This is a reproducible example:</p>
  
  <pre><code>public interface IClass1 { }
  
  public class Class1 : IClass1
  {
      private readonly IClass2 _class2;
  
      public Class1(IClass2 class2)
      {
          _class2 = class2; // This will be null
      }
  }
  
  public interface IClass2 { }
  
  public class Class2 : IClass2 { }
  
  public class Function1
  {
      private readonly IClass1 _class1;
      public Function1(IClass1 class1)
      {
          _class1 = class1;
      }
  
      [FunctionName("Function1")]
      public async Task&lt;HttpResponseMessage&gt; Run(
          [HttpTrigger(AuthorizationLevel.Anonymous,"post", Route = null)]
          HttpRequestMessage req,
          ILogger log)
      {
          log.LogInformation("C# HTTP trigger function processed a request.");
          return req.CreateResponse(HttpStatusCode.Accepted);
  
      }
  }
  </code></pre>
  
  <p>And put this in the <code>functionsStartup</code>: </p>
  
  <pre><code>[assembly: FunctionsStartup(typeof(Startup))]
  namespace FunctionApp2
  {
      public class Startup : FunctionsStartup
      {
          public override void Configure(IFunctionsHostBuilder builder)
          {
              builder.Services.AddSingleton&lt;IClass1, Class1&gt;();
              //builder.Services.AddSingleton&lt;IClass2, Class2&gt;(); // Leave this commented
          }
      }
  
  }
  </code></pre>