title: How to access the ASP.NET Core DI Container from within a class
body: <p>I am learning IoC &amp; DI with Asp.net core.
  I have setup my <code>DbContext</code> and other classes to be injected into my controllers.</p>
  <p>Currently my startup.cs looks like this:</p>
  <pre><code>// Add framework services.
  services.AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
      options.UseSqlServer(Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  
  
  services.AddIdentity&lt;ApplicationUser, IdentityRole&gt;(options =&gt;
  {
      options.Password.RequireDigit = false;
      options.Password.RequiredLength = 5;
      options.Password.RequireNonAlphanumeric = false;
      options.Password.RequireLowercase = false;
      options.Password.RequireUppercase = false;
  }).AddEntityFrameworkStores&lt;ApplicationDbContext&gt;()
      .AddDefaultTokenProviders();
  
  services.AddMvc();
  
  services.Configure&lt;AppSettings&gt;(Configuration.GetSection(&quot;AppSettings&quot;));
  </code></pre>
  <p>As you can see amongst other things I am injecting AppSettings class. I have no problem accessing this class like this:</p>
  <pre><code>private readonly AppSettings _appSettings;
  
  public HomeController(UserManager&lt;ApplicationUser&gt; userManager, 
      ApplicationDbContext dbContext,
      ViewRender view,
      IHostingEnvironment env,
      IOptions&lt;AppSettings&gt; appSettings
      )
  {
  }
  </code></pre>
  <p>Passing it into the constructor of a controller works fine.</p>
  <p>But I need to access the AppSettings in a class, and was hoping there was a static method I could use to inject the class into any random class. Is this possible? Or do I need to inject it into the controller and pass it to each other class?</p>