Microsoft.Extensions.Configuration.Binder 8.0.0-preview.5.23280.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.Identity.Web.TokenAcquisition
Implementation for higher level API for confidential client applications (ASP.NET Core and SDK/.NET).
|
4 |
Microsoft.Orleans.Reminders.AzureStorage
Microsoft Orleans reminders provider backed by Azure Table Storage
|
4 |
Aspire.Npgsql
A PostgreSQL® client that integrates with Aspire, including health checks, metrics, logging, and telemetry.
|
4 |
Aspire.Npgsql.EntityFrameworkCore.PostgreSQL
A PostgreSQL® provider for Entity Framework Core that integrates with Aspire, including connection pooling, health checks, logging, and telemetry.
|
4 |
Steeltoe.Common
Steeltoe common library
|
4 |
Microsoft.Extensions.Logging
Logging infrastructure default implementation for Microsoft.Extensions.Logging.
|
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/2aa401550574f93402eba13ff9a4827ef01a2f3a
|
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/610fe433e07b32ed451ed99d07df63be47c29050
|
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/e56abc45c4f8adc518abfc11a59849d616431e2c
|
3 |
Microsoft.AspNetCore.App
Microsoft.AspNetCore.App
|
3 |
Microsoft.Orleans.Persistence.AzureStorage
Microsoft Orleans persistence providers backed by Azure Storage
|
3 |
Aspire.Hosting.Testing
Testing support for the .NET Aspire application model.
|
3 |
Microsoft.Orleans.Core
Core library of Microsoft Orleans used both on the client and server.
|
3 |
Microsoft.AspNetCore.App
Provides a default set of APIs for building an ASP.NET Core application.
This package requires the ASP.NET Core runtime. This runtime is installed by the .NET Core SDK, or can be acquired separately using installers available at https://aka.ms/dotnet-download.
|
3 |
Microsoft.Identity.Web.TokenAcquisition
Implementation for higher level API for confidential client applications (ASP.NET Core and SDK/.NET).
|
3 |
.NET Framework 4.6.2
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.5.23280.8)
.NET 6.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.5.23280.8)
.NET 7.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.5.23280.8)
.NET 8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.5.23280.8)
.NET Standard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0-preview.5.23280.8)