title: Getting IConfiguration from ServiceCollection
body: <p>I´m writing my own extension method for <code>ServiceCollection</code> to registered the types of my module and I need to access the <code>IConfiguration</code> instance from the collection to register my Options. </p>
  
  <p><strong>Extension method</strong></p>
  
  <pre><code>public static IServiceCollection AddApi(this IServiceCollection services)
  {
    // Get configuration from collection
    var configuration = (IConfiguration) services.FirstOrDefault(p =&gt; p.ServiceType == typeof(IConfiguration)).ImplementationInstance;
  
    services.Configure&lt;DatabaseOptions&gt;(configuration.GetSection("Database"));
  }
  </code></pre>
  
  <p>Is this the right way to get the <code>IConfiguration</code> instance from the collection or is there a more elegant solution? I do not want to add the IConfiguration instance as parameter to the method.</p>