forked from dotnet/AspNetCore.Docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update UsingOptions sample app (dotnet#4214)
* Update UsingOptions sample app Takes sample to 2.0 * Update with view option injection Fixes dotnet#437 Update Update
- Loading branch information
1 parent
725d2b5
commit 500386e
Showing
16 changed files
with
131 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Controllers/HomeController2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Controllers/HomeController3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//#define First | ||
#if First | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
using UsingOptions.Models; | ||
|
||
namespace UsingOptions.Controllers | ||
{ | ||
public class HomeController : Controller | ||
{ | ||
private readonly MyOptions _options; | ||
|
||
public HomeController(IOptions<MyOptions> optionsAccessor) | ||
{ | ||
_options = optionsAccessor.Value; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(_options); | ||
} | ||
} | ||
} | ||
#endif |
17 changes: 10 additions & 7 deletions
17
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Models/MyOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
public class MyOptions | ||
namespace UsingOptions.Models | ||
{ | ||
public MyOptions() | ||
public class MyOptions | ||
{ | ||
// Set default value. | ||
Option1 = "value1_from_ctor"; | ||
public MyOptions() | ||
{ | ||
// Set default value. | ||
Option1 = "value1_from_ctor"; | ||
} | ||
public string Option1 { get; set; } | ||
public int Option2 { get; set; } = 5; | ||
} | ||
public string Option1 { get; set; } | ||
public int Option2 { get; set; } = 5; | ||
} | ||
} |
19 changes: 12 additions & 7 deletions
19
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Models/MySubOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
public class MySubOptions | ||
namespace UsingOptions.Models | ||
{ | ||
public MySubOptions() | ||
#region snippet1 | ||
public class MySubOptions | ||
{ | ||
// Set default values. | ||
SubOption1 = "value1_from_ctor"; | ||
SubOption2 = 5; | ||
public MySubOptions() | ||
{ | ||
// Set default values. | ||
SubOption1 = "value1_from_ctor"; | ||
SubOption2 = 5; | ||
} | ||
public string SubOption1 { get; set; } | ||
public int SubOption2 { get; set; } | ||
} | ||
public string SubOption1 { get; set; } | ||
public int SubOption2 { get; set; } | ||
#endregion | ||
} |
20 changes: 9 additions & 11 deletions
20
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,19 @@ | ||
using System.IO; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
namespace UsingOptions | ||
{ | ||
public static class Program | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel() | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
BuildWebHost(args).Run(); | ||
} | ||
|
||
public static IWebHost BuildWebHost(string[] args) => | ||
WebHost.CreateDefaultBuilder(args) | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} | ||
} |
19 changes: 0 additions & 19 deletions
19
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/Properties/launchSettings.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 2 additions & 17 deletions
19
aspnetcore/fundamentals/configuration/sample/src/UsingOptions/UsingOptions.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp1.0</TargetFramework> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
<AssemblyName>UsingOptions</AssemblyName> | ||
<OutputType>Exe</OutputType> | ||
<PackageId>UsingOptions</PackageId> | ||
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion> | ||
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.3" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration" 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.Options.ConfigurationExtensions" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" /> | ||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.