Update to ASP.net Configuration page (#23369)
Co-authored-by: Kirk Larkin <6025110+serpent5@users.noreply.github.com>pull/24033/head
parent
26cab4819b
commit
56cb8cec1d
|
@ -774,6 +774,14 @@ The following code shows how to use the custom `EFConfigurationProvider` in *Pro
|
||||||
|
|
||||||
[!code-csharp[](index/samples_snippets/6.x/EfconfigSample/Program.cs?highlight=5-6)]
|
[!code-csharp[](index/samples_snippets/6.x/EfconfigSample/Program.cs?highlight=5-6)]
|
||||||
|
|
||||||
|
## Access configuration with Dependency Injection (DI)
|
||||||
|
|
||||||
|
Configuration can be injected into services using [Dependency Injection (DI)](xref:fundamentals/dependency-injection) by resolving the <xref:Microsoft.Extensions.Configuration.IConfiguration> service:
|
||||||
|
|
||||||
|
[!code-csharp[](index/samples/6.x/ConfigSample/Service.cs?name=snippet_Class&highlight=5-6)]
|
||||||
|
|
||||||
|
For information on how to access values using `IConfiguration`, see [GetValue](#getvalue) and [GetSection, GetChildren, and Exists](#getsection-getchildren-and-exists) in this article.
|
||||||
|
|
||||||
## Access configuration in Razor Pages
|
## Access configuration in Razor Pages
|
||||||
|
|
||||||
The following code displays configuration data in a Razor Page:
|
The following code displays configuration data in a Razor Page:
|
||||||
|
@ -1451,7 +1459,7 @@ In the preceding environment variable, `Https` is the name of the Kestrel specif
|
||||||
|
|
||||||
## GetValue
|
## GetValue
|
||||||
|
|
||||||
[`ConfigurationBinder.GetValue<T>`](xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue*) extracts a single value from configuration with a specified key and converts it to the specified type:
|
[`ConfigurationBinder.GetValue<T>`](xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue*) extracts a single value from configuration with a specified key and converts it to the specified type. This method is an extension method for <xref:Microsoft.Extensions.Configuration.IConfiguration>:
|
||||||
|
|
||||||
[!code-csharp[](index/samples/3.x/ConfigSample/Pages/TestNum.cshtml.cs?name=snippet)]
|
[!code-csharp[](index/samples/3.x/ConfigSample/Pages/TestNum.cshtml.cs?name=snippet)]
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
namespace ConfigSample
|
||||||
|
{
|
||||||
|
#region snippet_Class
|
||||||
|
public class Service
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _config;
|
||||||
|
|
||||||
|
public Service(IConfiguration config) =>
|
||||||
|
_config = config;
|
||||||
|
|
||||||
|
public void DoSomething()
|
||||||
|
{
|
||||||
|
var configSettingValue = _config["ConfigSetting"];
|
||||||
|
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
Loading…
Reference in New Issue