title: Passing IOptions into .Net core middleware class for json config retrieval
body: <p>I'm trying to use strongly typed json config settings as per the <a href="http://andrewlock.net/how-to-use-the-ioptions-pattern-for-configuration-in-asp-net-core-rc2/" rel="nofollow noreferrer">Options pattern</a> in .net core. All examples so far show how easy it is to inject the strongly typed settings class into a controller but I need to use it in a middleware class (Very similar to <a href="https://stackoverflow.com/questions/32792245/how-to-pass-ioptions-to-an-asp-net-5-middle-ware-service">this question</a> but I'm no further forward after trying it that way).</p>
  
  <p>So, the setup:</p>
  
  <p><strong>mysettings.json</strong></p>
  
  <pre><code>{
    "MySettings": {
      "Name": "Some Name from config",
      "Description": "Some Description from config"
    }
  }
  </code></pre>
  
  <p><strong>mysettings.cs</strong></p>
  
  <pre><code>public class MySettings
  {
      public string Name { get; set; } = "Default name";
  
      public string Description { get; set; } = "Default description";
  }
  </code></pre>
  
  <p><strong>startup.cs</strong></p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc();
  
      // Add functionality to inject IOptions&lt;T&gt;
      services.AddOptions();
  
      // Add our Config object so it can be injected
      services.Configure&lt;MySettings&gt;(Configuration.GetSection("MySettings"));
      services.AddSingleton&lt;IMySettingsService, MySettingsService&gt;();
  }
  </code></pre>
  
  <p><strong>MysettingsService.cs</strong></p>
  
  <pre><code>public class MysettingsService : IMysettingsService
  {
      private MySettings mySettings { get; set; }
  
      public MysettingsService (MySettings _mySettings)
      {
          mySettings = _mySettings.value;
      }
  
      public string GetName()
      {
          return mySettings.Name; 
      }
  }
  </code></pre>
  
  <p>How do I go about instantiating <strong>MysettingsService.cs</strong> and injecting an <code>IOptions&lt;MySettings&gt;</code> into the class constructor so I can call the <strong>GetName</strong> method?</p>