title: How to use Dependency Injection in .Net core Console Application
body: <p>I have to add data to my database using a Console Application. In the Main() method I added:</p>
  
  <pre><code>var services = new ServiceCollection();
  var serviceProvider = services.BuildServiceProvider();
  var connection = @"Server = (localdb)\mssqllocaldb; Database = CryptoCurrency; Trusted_Connection = True; ConnectRetryCount = 0";
  services.AddDbContext&lt;CurrencyDbContext&gt;(options =&gt; options.UseSqlServer(connection));
  </code></pre>
  
  <p>In another class I add functionality to work with database, and made it like a Web Api application and added my DbContext into constructor:</p>
  
  <pre><code>public AutoGetCurrency(CurrencyDbContext db) =&gt;  this.db = new CurrencyDbContext();
  </code></pre>
  
  <p>This gives the following error:</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object</p>
  </blockquote>
  
  <p>I tried to add a default constructor without parameters, and it still gives the same error.</p>
  
  <p>Please tell me how I can use DI in .Net core console application ?</p>