title: Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'myContext' to type DataContext. error in Azure Function v2
body: <p>Requirement: Create Azure Function which can inject <code>Entity Framework</code> context 
   to <code>Run</code> method using dependency injection.</p>
  
  <p>Here is my <code>Startup</code> class</p>
  
  <pre><code>   [assembly: WebJobsStartup(typeof(Startup))]
     namespace MessagesToSqlDbFuncApp
     {
         internal class Startup : IWebJobsStartup
         {
          public void Configure(IWebJobsBuilder builder) =&gt;
          builder.AddDependencyInjection&lt;ServiceProviderBuilder&gt;();
         }
     }
  </code></pre>
  
  <p>Here is <code>ServiceProviderBuilder</code> class</p>
  
  <pre><code>public class ServiceProviderBuilder : IServiceProviderBuilder
  {
      public IServiceProvider Build()
      {
          IConfigurationRoot config = new ConfigurationBuilder()
              .SetBasePath(Environment.CurrentDirectory)
              .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
              .AddEnvironmentVariables()
              .Build();
  
          var connectionString = config.GetConnectionString("SqlConnectionString");
  
          var services = new ServiceCollection();
  
          services.AddDbContext&lt;DataContext&gt;(options =&gt; options.UseSqlServer(connectionString));
  
          return services.BuildServiceProvider(true);
      }
  }
  </code></pre>
  
  <p>This is my function</p>
  
  <pre><code>   [FunctionName("MessagesToSqlDbFuncApp")]
      public static async Task Run([BlobTrigger("messagecontainer/{name}", Connection = "AzureWebJobsStorage")]
          Stream myBlob, 
          string name, 
          ILogger log,
          [Inject] DataContext myContext)
      {
  
      }
  </code></pre>
  
  <p>Here is the error which thrown while running the funciton</p>
  
  <blockquote>
    <p>[2/20/2019 4:25:10 AM] Error indexing method 'MessagesToSqlDbFuncApp'
    [2/20/2019 4:25:10 AM] Microsoft.Azure.WebJobs.Host: Error indexing method 'BlobQCMessagesToSqlDbFuncApp'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'myContext' to type DataContext. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).</p>
  </blockquote>
  
  <p>Here is the nuget packages and versions</p>
  
  <ul>
  <li>Azure Function Version : 2</li>
  <li>Visual Studio : 2017</li>
  <li>Microsoft.EntityFrameworkCore: 2.1.4</li>
  <li>Microsoft.EntityFrameworkCore.Design: 2.1.4 </li>
  <li>Microsoft.EntityFrameworkCore.SqlServer: 2.1.4</li>
  <li>Microsoft.Extensions.DependencyInjection: 2.2.0</li>
  <li>Microsoft.NET.Sdk.Functions: 1.0.24</li>
  <li>Microsoft.NETCore.App: 2.1.0</li>
  </ul>
  
  <p><strong>Important Note:</strong> Debugger is not hitting the <code>Startup</code> class!. How do I initialize the <code>startup</code> class?</p>