Update ObjectGraph sample app (#4201)

Addresses #1950

Takes sample to 2.0
pull/4210/head
Luke Latham 2017-09-05 10:43:57 -05:00 committed by Scott Addie
parent d9b765cfbf
commit 6d2cc2a11d
4 changed files with 14 additions and 18 deletions

View File

@ -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:

View File

@ -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>

View File

@ -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();
}
}

View File

@ -11,4 +11,4 @@
"Width": "11"
}
}
}
}