title: How to use IConfiguration object that I built in my Startup class in some other class?
body: <p>We are using asp.net core to build our web application. Below is our code which starts the server and passing all the values to underlying classes. This is the way it was designed from starting.</p>
  <pre><code>public class ProgramApiServer : IWebServer
  {
      public void StartServer()
      {
          var host = new WebHostBuilder()
              .UseContentRoot(Directory.GetCurrentDirectory())
              .UseKestrel(o =&gt;
              {
                  o.Limits.MaxResponseBufferSize = null;
                  o.Limits.MinResponseDataRate = null;
                  o.Limits.MaxConcurrentConnections = 1000;
                  o.Limits.MaxConcurrentUpgradedConnections = 1000;
                  o.AllowSynchronousIO = true;
              })
              .UseStartup&lt;Startup&gt;()
              .UseUrls(&quot;http://*:1330&quot;)
              .Build();
          host.Run();
      }
  }
  </code></pre>
  <p>This is what I have in my <code>Startup</code> class:</p>
  <pre><code>public Startup(IHostingEnvironment env)
  {
      var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile(&quot;clientsettings.json&quot;, optional: true, reloadOnChange: true)
          .AddJsonFile($&quot;clientsettings.{env.EnvironmentName}.json&quot;, optional: true)
          .AddEnvironmentVariables();
      // building IConfiguration object here
      Configuration = builder.Build();
  }
  
  // how can I use this in DataProcess class
  public IConfigurationRoot Configuration { get; }
  
  public void ConfigureServices(IServiceCollection services)
  {
      // ...
      DataProcess.Evaluate(services);
      // ...
  }
  
  public void Configure(IApplicationBuilder app, IHostApplicationLifetime lifetime)
  {
      // some stuff here
  }
  </code></pre>
  <p>Below is my <code>DataProcess</code> class:</p>
  <pre><code>public static class DataProcess {
  
      public static void Evaluate(IServiceCollection services)
      {
          // ...
          Process(services, ....);
      }
  
      private static void Process(IServiceCollection services, ....) 
      {
          // ...
  
          // here I need to use IConfiguration object to get value for my config
          Console.WriteLine(_configuration[&quot;configKey&quot;]);
      }
  }
  </code></pre>
  <p><strong>Question:</strong></p>
  <p>As you can see above I am calling <code>Evaluate</code> method of <code>DataProcess</code> class from <code>ConfigureServices</code> method of <code>Startup</code> class. I need to use <code>IConfiguration</code> object in <code>Process</code> method of <code>DataProcess</code> class but I am not able to figure it out on how can I use it.</p>
  <p>I recently started working with asp.net and trying to see on how can I pass around the <code>IConfiguration</code> object cleanly to my static <code>DataProcess</code> class. Is it a good idea to pass it via <code>Evaluate</code> method in <code>Startup</code> class and then store it in global variable in <code>DataProcess</code> class that can be used in <code>Process</code> method or any other better way?</p>