Update configuration.rst (#1669)
- Make it a little more obvious that `IConfigureOptions<TOptions>` can be implemented in order to configure some options using things from the service container. - Correct the reference to the extension method used to register an instance of `IConfigureOptions<TOptions>`. - Fix a grammatical error.pull/1688/head
parent
592d0b4f69
commit
b7c231160e
|
@ -137,7 +137,7 @@ You configure options using the :dn:method:`~Microsoft.Extensions.DependencyInje
|
|||
|
||||
When you bind options to configuration, each property in your options type is bound to a configuration key of the form ``property:subproperty:...``. For example, the ``MyOptions.Option1`` property is bound to the key ``Option1``, which is read from the ``option1`` property in *appsettings.json*. Note that configuration keys are case insensitive.
|
||||
|
||||
Each call to :dn:method:`~Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure\<TOptions>` adds an :dn:iface:`~Microsoft.Extensions.Options.IConfigureOptions\<TOptions>` service to the service container that is used by the :dn:iface:`~Microsoft.Extensions.Options.IOptions\<TOptions>` service to provide the configured options to the application or framework. If you want to configure your options some other way (for example, reading settings from a database) you can use the ``AddSingleton<TOptions>`` extension method to you specify a custom :dn:iface:`~Microsoft.Extensions.Options.IConfigureOptions\<TOptions>` service directly.
|
||||
Each call to :dn:method:`~Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure\<TOptions>` adds an :dn:iface:`~Microsoft.Extensions.Options.IConfigureOptions\<TOptions>` service to the service container that is used by the :dn:iface:`~Microsoft.Extensions.Options.IOptions\<TOptions>` service to provide the configured options to the application or framework. If you want to configure your options using objects that must be obtained from the service container (for example, to read settings from a database) you can use the ``AddSingleton<IConfigureOptions<TOptions>>`` extension method to register a custom :dn:iface:`~Microsoft.Extensions.Options.IConfigureOptions\<TOptions>` service.
|
||||
|
||||
You can have multiple :dn:iface:`~Microsoft.Extensions.Options.IConfigureOptions\<TOptions>` services for the same option type and they are all applied in order. In the :ref:`example <options-example>` above, the values of ``Option1`` and ``Option2`` are both specified in `appsettings.json`, but the value of ``Option1`` is overridden by the configured delegate with the value "value1_from_action".
|
||||
|
||||
|
|
Loading…
Reference in New Issue