Converting IConfigurationSection to IOptions

you can also use

config.Get<MyCustomOptions>()

This is an extension method from Microsoft.Extensions.Configuration namespace. I see it in Assembly Microsoft.Extensions.Configuration.Binder, Version=3.1.9.0. Perhaps, it exists in earlier versions also. That would give you the Settings object itself. then you can wrap it into IOptions as Krik showed in another answer.


You can use the Bind(Configuration, object) extension method to perform manual binding of any object. Here's an example:

var myCustomOptions = new MyCustomOptions();
myConfigurationSection.Bind(myCustomOptions);

// Use myCustomOptions directly.

To wrap this in an IOptions<T>, use Options.Create:

IOptions<MyCustomOptions> myOptions = Options.Create(myCustomOptions);