-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30881 from dotnet/main
Merge to Live
- Loading branch information
Showing
76 changed files
with
41,148 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/ConfigSample.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
</Project> |
11 changes: 11 additions & 0 deletions
11
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyArray.json
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,11 @@ | ||
{ | ||
"array": { | ||
"entries": { | ||
"0": "value00", | ||
"1": "value10", | ||
"2": "value20", | ||
"4": "value40", | ||
"5": "value50" | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...tcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyConfig.Development.json
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,15 @@ | ||
{ | ||
"Position": { | ||
"Title": "Dev My Config title", | ||
"Name": "Dev My Config Smith" | ||
}, | ||
"MyKey": "MyConfig.Development.json Value", | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
12 changes: 12 additions & 0 deletions
12
...etcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyConfig.Production.json
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,12 @@ | ||
{ | ||
"Position": { | ||
"Title": "Production writer", | ||
"Name": "Production Smith" | ||
}, | ||
"MyKey": "Production appsettings.Production Value", | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Information", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyConfig.json
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,15 @@ | ||
{ | ||
"Position": { | ||
"Title": "My Config title", | ||
"Name": "My Config Smith" | ||
}, | ||
"MyKey": "MyConfig.json Value", | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
1 change: 1 addition & 0 deletions
1
...ore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyIniConfig.Development.ini
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 @@ | ||
MyKey="MyIniConfig.ini Value from Dev" |
9 changes: 9 additions & 0 deletions
9
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyIniConfig.ini
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,9 @@ | ||
MyKey="MyIniConfig.ini Value" | ||
|
||
[Position] | ||
Title="My INI Config title" | ||
Name="My INI Config name" | ||
|
||
[Logging:LogLevel] | ||
Default=Information | ||
Microsoft=Warning |
20 changes: 20 additions & 0 deletions
20
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MySubsection.json
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,20 @@ | ||
{ | ||
"section0": { | ||
"key0": "value00", | ||
"key1": "value01" | ||
}, | ||
"section1": { | ||
"key0": "value10", | ||
"key1": "value11" | ||
}, | ||
"section2": { | ||
"subsection0": { | ||
"key0": "value200", | ||
"key1": "value201" | ||
}, | ||
"subsection1": { | ||
"key0": "value210", | ||
"key1": "value211" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyXMLFile.xml
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<MyKey>MyXMLFile Value</MyKey> | ||
<Position> | ||
<Title>Title from MyXMLFile</Title> | ||
<Name>Name from MyXMLFile</Name> | ||
</Position> | ||
<Logging> | ||
<LogLevel> | ||
<Default>Information</Default> | ||
<Microsoft>Warning</Microsoft> | ||
</LogLevel> | ||
</Logging> | ||
</configuration> |
11 changes: 11 additions & 0 deletions
11
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/MyXMLFile3.xml
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<configuration> | ||
<section name="section0"> | ||
<key name="key0">value 00</key> | ||
<key name="key1">value 01</key> | ||
</section> | ||
<section name="section1"> | ||
<key name="key0">value 10</key> | ||
<key name="key1">value 11</key> | ||
</section> | ||
</configuration> |
9 changes: 9 additions & 0 deletions
9
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/ArrayExample.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,9 @@ | ||
namespace ConfigSample.Options | ||
{ | ||
#region snippet | ||
public class ArrayExample | ||
{ | ||
public string[]? Entries { get; set; } | ||
} | ||
#endregion | ||
} |
10 changes: 10 additions & 0 deletions
10
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/ColorOptions.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,10 @@ | ||
namespace ConfigSample.Options | ||
{ | ||
public class ColorOptions | ||
{ | ||
public const string Color = "Color"; | ||
|
||
public string Foreground { get; set; } = String.Empty; | ||
public string Background { get; set; } = String.Empty; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...nfiguration/index/samples/8.x/ConfigSample/Options/MyConfigServiceCollectionExtensions.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,28 @@ | ||
using ConfigSample.Options; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static class MyConfigServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddConfig( | ||
this IServiceCollection services, IConfiguration config) | ||
{ | ||
services.Configure<PositionOptions>( | ||
config.GetSection(PositionOptions.Position)); | ||
services.Configure<ColorOptions>( | ||
config.GetSection(ColorOptions.Color)); | ||
|
||
return services; | ||
} | ||
|
||
public static IServiceCollection AddMyDependencyGroup( | ||
this IServiceCollection services) | ||
{ | ||
services.AddScoped<IMyDependency, MyDependency>(); | ||
services.AddScoped<IMyDependency2, MyDependency2>(); | ||
|
||
return services; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...core/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/PositionOptions.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,12 @@ | ||
namespace ConfigSample.Options | ||
{ | ||
#region snippet | ||
public class PositionOptions | ||
{ | ||
public const string Position = "Position"; | ||
|
||
public string Title { get; set; } = String.Empty; | ||
public string Name { get; set; } = String.Empty; | ||
} | ||
#endregion | ||
} |
54 changes: 54 additions & 0 deletions
54
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Options/Widgets.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,54 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection.ConfigSample.Options | ||
{ | ||
public interface IMyDependency | ||
{ | ||
void WriteMessage(string message); | ||
} | ||
|
||
public class MyDependency : IMyDependency | ||
{ | ||
private readonly ILogger<MyDependency> _logger; | ||
|
||
public MyDependency(ILogger<MyDependency> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public void WriteMessage(string message) | ||
{ | ||
_logger.LogInformation( | ||
$"MyDependency.WriteMessage called. Message: {message}"); | ||
} | ||
} | ||
public interface IMyDependency2 | ||
{ | ||
void WriteMessage(string message); | ||
} | ||
|
||
public class MyDependency2 : IMyDependency2 | ||
{ | ||
private readonly ILogger<MyDependency2> _logger; | ||
|
||
public MyDependency2(ILogger<MyDependency2> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public void WriteMessage(string message) | ||
{ | ||
_logger.LogInformation( | ||
$"MyDependency2.WriteMessage called. Message: {message}"); | ||
} | ||
} | ||
|
||
public static class MyDependencyServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddMyDependencyGroup(this IServiceCollection services) | ||
{ | ||
services.AddScoped<IMyDependency, MyDependency>(); | ||
return services; | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Array.cshtml
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,4 @@ | ||
@page | ||
@model ConfigSample.ArrayModel | ||
|
||
Markup not displayed. |
37 changes: 37 additions & 0 deletions
37
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Array.cshtml.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,37 @@ | ||
using ConfigSample.Options; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ConfigSample | ||
{ | ||
// <snippet> | ||
public class ArrayModel : PageModel | ||
{ | ||
private readonly IConfiguration Config; | ||
public ArrayExample? _array { get; private set; } | ||
|
||
public ArrayModel(IConfiguration config) | ||
{ | ||
Config = config; | ||
} | ||
|
||
public ContentResult OnGet() | ||
{ | ||
_array = Config.GetSection("array").Get<ArrayExample>(); | ||
if (_array == null) | ||
{ | ||
throw new ArgumentNullException(nameof(_array)); | ||
} | ||
string s = String.Empty; | ||
|
||
for (int j = 0; j < _array.Entries.Length; j++) | ||
{ | ||
s += $"Index: {j} Value: {_array.Entries[j]} \n"; | ||
} | ||
|
||
return Content(s); | ||
} | ||
} | ||
// </snippet> | ||
} |
26 changes: 26 additions & 0 deletions
26
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Error.cshtml
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,26 @@ | ||
@page | ||
@model ErrorModel | ||
@{ | ||
ViewData["Title"] = "Error"; | ||
} | ||
|
||
<h1 class="text-danger">Error.</h1> | ||
<h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
||
@if (Model.ShowRequestId) | ||
{ | ||
<p> | ||
<strong>Request ID:</strong> <code>@Model.RequestId</code> | ||
</p> | ||
} | ||
|
||
<h3>Development Mode</h3> | ||
<p> | ||
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred. | ||
</p> | ||
<p> | ||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong> | ||
It can result in displaying sensitive information from exceptions to end users. | ||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> | ||
and restarting the app. | ||
</p> |
26 changes: 26 additions & 0 deletions
26
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Error.cshtml.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,26 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using System.Diagnostics; | ||
|
||
namespace ConfigSample.Pages; | ||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] | ||
[IgnoreAntiforgeryToken] | ||
public class ErrorModel : PageModel | ||
{ | ||
public string? RequestId { get; set; } | ||
|
||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); | ||
|
||
private readonly ILogger<ErrorModel> _logger; | ||
|
||
public ErrorModel(ILogger<ErrorModel> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public void OnGet() | ||
{ | ||
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; | ||
} | ||
} | ||
|
10 changes: 10 additions & 0 deletions
10
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Index.cshtml
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,10 @@ | ||
@page | ||
@model IndexModel | ||
@{ | ||
ViewData["Title"] = "Home page"; | ||
} | ||
|
||
<div class="text-center"> | ||
<h1 class="display-4">Welcome</h1> | ||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p> | ||
</div> |
18 changes: 18 additions & 0 deletions
18
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Index.cshtml.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,18 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace ConfigSample.Pages; | ||
public class IndexModel : PageModel | ||
{ | ||
private readonly ILogger<IndexModel> _logger; | ||
|
||
public IndexModel(ILogger<IndexModel> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
public void OnGet() | ||
{ | ||
|
||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
aspnetcore/fundamentals/configuration/index/samples/8.x/ConfigSample/Pages/Index2.cshtml
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,4 @@ | ||
@page | ||
@model Index2Model | ||
|
||
<p>This content is never used. The preceding directives are required in Razor Pages.</p> |
Oops, something went wrong.