title: Save configuration through custom options class in asp.net core
body: <p>I wrote a Configuration provider according to <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration#in-memory-provider-and-binding-to-a-poco-class" rel="nofollow noreferrer">this (Basic sample of Entity Framework custom provider)</a> article.</p>
  
  <p>There I also override the Set method of the <a href="https://github.com/aspnet/Configuration/blob/dev/src/Microsoft.Extensions.Configuration/ConfigurationProvider.cs" rel="nofollow noreferrer">base class</a> to save the configuration back to the database.</p>
  
  <pre><code>public virtual void Set(string key, string value)
  {
     // save key / value pair to db.
  }
  </code></pre>
  
  <p>This also works fine if I save the configuration like this:</p>
  
  <pre><code>IConfiguration configuration = ...
  configuration["Key"] = "value";
  </code></pre>
  
  <p>But this does not work if I want to save it through a custom options class:</p>
  
  <pre><code>public class MyOptions
  {
     public string Key { get; set; }
  }
  
  public class HomeController : Controller
  {
      private readonly MyOptions _options;
  
      public HomeController(IOptions&lt;MyOptions&gt; optionsAccessor)
      {
          _options = optionsAccessor.Value;
      }
  
      public IActionResult Index()
      {
          _options.Key = "new value"; // &lt;-- not calling the set in my provider
      }
  }
  </code></pre>
  
  <p>Has someone an idea how to solve this?</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I know that the configuration framework is not able to track changes I did to <code>MyOptions</code> and therefor it cannot update it automagically. But is there an other way to trigger to save the configuration?</p>