parent
d9b765cfbf
commit
6d2cc2a11d
|
@ -201,7 +201,7 @@ You can recursively bind to each object in a class. Consider the following `AppO
|
|||
|
||||
The following sample binds to the `AppOptions` class:
|
||||
|
||||
[!code-csharp[Main](configuration/sample/src/ObjectGraph/Program.cs?highlight=19-20)]
|
||||
[!code-csharp[Main](configuration/sample/src/ObjectGraph/Program.cs?highlight=15-16)]
|
||||
|
||||
**ASP.NET Core 1.1** and higher can use `Get<T>`, which works with entire sections. `Get<T>` can be more convienent than using `Bind`. The following code shows how to use `Get<T>` with the sample above:
|
||||
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||
<AssemblyName>ObjectGraph</AssemblyName>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<PackageId>ObjectGraph</PackageId>
|
||||
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
|
||||
<PackageTargetFallback>$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
// Add these NuGet packages:
|
||||
// "Microsoft.Extensions.Configuration.Binder"
|
||||
// "Microsoft.Extensions.Configuration.FileExtensions"
|
||||
// "Microsoft.Extensions.Configuration.Json":
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args = null)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json");
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json");
|
||||
|
||||
var config = builder.Build();
|
||||
|
||||
|
@ -20,5 +16,9 @@ public class Program
|
|||
config.GetSection("App").Bind(appConfig);
|
||||
|
||||
Console.WriteLine($"Height {appConfig.Window.Height}");
|
||||
Console.WriteLine();
|
||||
|
||||
Console.WriteLine("Press a key...");
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
"Width": "11"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue