title: Correct way to get instance of IHostingServices
body: <p>In ASP.NET 5 core there is an interface, IHostingEnvironment, but looking at the samples and source code for ASP.NET there are 3 different ways to obtain an instance.</p>
  
  <p>Using an attribute...</p>
  
  <pre><code>[FromServices]
  public IHostingEnvironment HostingEnvironment { get; set; }
  </code></pre>
  
  <p>As an argument passed via the configure method in the Startup class...</p>
  
  <pre><code>public void Configure(IApplicationBuilder application, IHostingEnvironment environment)
  {
  }
  </code></pre>
  
  <p>Or by using DI with either of the following lines...</p>
  
  <pre><code>var hostingEnvironment = requestServices.GetService&lt;IHostingEnvironment&gt;();
  var hostingEnvironment = app.ApplicationServices.GetRequiredService&lt;IHostingEnvironment&gt;();
  </code></pre>
  
  <p>What is not clear is which is the correct method to use.</p>
  
  <p>As an example of how unclear it can be, if a call is made to a method which requires an instance of a class which implements the IHostingEnvironment from within the Startup class, should the instance be passed as an argument in the method call, should DI be used or something else?</p>