Microsoft.Extensions.Configuration.Binder 8.0.0-preview.3.23174.8
About
Provides the functionality to bind an object to data in configuration providers for Microsoft.Extensions.Configuration. This package enables you to represent the configuration data as strongly-typed classes defined in the application code. To bind a configuration, use the Microsoft.Extensions.Configuration.ConfigurationBinder.Get extension method on the IConfiguration
object. To use this package, you also need to install a package for the configuration provider, for example, Microsoft.Extensions.Configuration.Json for the JSON provider.
For more information, see the documentation: Configuration in .NET.
Example
The following example shows how to bind a JSON configuration section to .NET objects.
using System;
using Microsoft.Extensions.Configuration;
class Settings
{
public string Server { get; set; }
public string Database { get; set; }
public Endpoint[] Endpoints { get; set; }
}
class Endpoint
{
public string IPAddress { get; set; }
public int Port { get; set; }
}
class Program
{
static void Main()
{
// Build a configuration object from JSON file
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
// Bind a configuration section to an instance of Settings class
Settings settings = config.GetSection("Settings").Get<Settings>();
// Read simple values
Console.WriteLine($"Server: {settings.Server}");
Console.WriteLine($"Database: {settings.Database}");
// Read nested objects
Console.WriteLine("Endpoints: ");
foreach (Endpoint endpoint in settings.Endpoints)
{
Console.WriteLine($"{endpoint.IPAddress}:{endpoint.Port}");
}
}
}
To run this example, include an appsettings.json
file with the following content in your project:
{
"Settings": {
"Server": "example.com",
"Database": "Northwind",
"Endpoints": [
{
"IPAddress": "192.168.0.1",
"Port": "80"
},
{
"IPAddress": "192.168.10.1",
"Port": "8080"
}
]
}
}
You can include a configuration file using a code like this in your .csproj
file:
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
Showing the top 20 packages that depend on Microsoft.Extensions.Configuration.Binder.
Packages | Downloads |
---|---|
Microsoft.Extensions.Logging
Logging infrastructure default implementation for Microsoft.Extensions.Logging.
|
8 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/50b7e9c661453874aa7a54a3985d5120564bb2e5
|
4 |
Microsoft.Extensions.Logging
Logging infrastructure default implementation for Microsoft.Extensions.Logging.
This package was built from the source code at https://github.com/aspnet/Extensions/tree/9bc79b2f25a3724376d7af19617c33749a30ea3a
|
4 |
Microsoft.Extensions.Logging
Logging infrastructure default implementation for Microsoft.Extensions.Logging.
|
4 |
Microsoft.Identity.Web.TokenAcquisition
Implementation for higher level API for confidential client applications (ASP.NET Core and SDK/.NET).
|
4 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/f0f9de5692adf1c0576de062f93c6ab7b176433f
|
4 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/68bb6fb08f8f85bb3cf08953a0d2f4a254eaccff
|
3 |
Microsoft.Extensions.Logging.Configuration
Configuration support for Microsoft.Extensions.Logging.
When using NuGet 3.x this package requires at least version 3.4.
|
3 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/bb01bbf4433e27289b99001b7de6a582879d1835
|
3 |
Microsoft.Extensions.Options.ConfigurationExtensions
Provides additional configuration specific functionality related to Options.
|
3 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/cd9340856ed85215a911c97c44d52373f6cba2f9
|
2 |
Microsoft.Extensions.Hosting
Hosting and startup infrastructures for applications.
When using NuGet 3.x this package requires at least version 3.4.
|
2 |
Serilog.Settings.Configuration
Microsoft.Extensions.Configuration (appsettings.json) support for Serilog.
|
2 |
Microsoft.Extensions.Logging
Logging infrastructure default implementation for Microsoft.Extensions.Logging.
|
2 |
Microsoft.AspNetCore.Components.WebAssembly
Build client-side single-page applications (SPAs) with Blazor running under WebAssembly.
This package was built from the source code at https://github.com/dotnet/aspnetcore/tree/ae1a6cbe225b99c0bf38b7e31bf60cb653b73a52
|
2 |
Microsoft.Extensions.Options.ConfigurationExtensions
Provides additional configuration specific functionality related to Options.
|
2 |
Microsoft.Identity.Web.TokenAcquisition
Implementation for higher level API for confidential client applications (ASP.NET Core and SDK/.NET).
|
2 |
Microsoft.Extensions.Http.Diagnostics
Telemetry support for HTTP Client.
|
2 |
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions.
|
2 |
.NET Framework 4.6.2
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.3.23174.8)
.NET 6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.3.23174.8)
.NET 7.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.3.23174.8)
.NET 8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.3.23174.8)
.NET Standard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.3.23174.8)