diff --git a/aspnetcore/diagnostics/asp0003.md b/aspnetcore/diagnostics/asp0003.md index 0bbd9681dd..3f40c1f489 100644 --- a/aspnetcore/diagnostics/asp0003.md +++ b/aspnetcore/diagnostics/asp0003.md @@ -1,7 +1,7 @@ --- title: "ASP0003: Do not use action results with route handlers" description: "Learn about analysis rule ASP0003: Do not use action results with route handlers" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.date: 10/21/2021 diff --git a/aspnetcore/diagnostics/asp0004.md b/aspnetcore/diagnostics/asp0004.md index f67b2ab12b..632da9c760 100644 --- a/aspnetcore/diagnostics/asp0004.md +++ b/aspnetcore/diagnostics/asp0004.md @@ -1,7 +1,7 @@ --- title: "ASP0004: Do not use action results with route handlers" description: "Learn about analysis rule ASP0004: Do not use action results with route handlers" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.date: 10/21/2021 diff --git a/aspnetcore/diagnostics/asp0005.md b/aspnetcore/diagnostics/asp0005.md index 5c185c7064..5b06066294 100644 --- a/aspnetcore/diagnostics/asp0005.md +++ b/aspnetcore/diagnostics/asp0005.md @@ -1,7 +1,7 @@ --- title: "ASP0005: Do not place attribute on method called by route handler lambda" description: "Learn about analysis rule ASP0005: Do not place attribute on method called by route handler lambda" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.date: 10/21/2021 diff --git a/aspnetcore/diagnostics/asp0006.md b/aspnetcore/diagnostics/asp0006.md index 0bc813466b..577abb297b 100644 --- a/aspnetcore/diagnostics/asp0006.md +++ b/aspnetcore/diagnostics/asp0006.md @@ -1,7 +1,7 @@ --- title: "ASP0006: Do not use non-literal sequence numbers" description: "Learn about analysis rule ASP0006: Do not use non-literal sequence numbers" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.date: 10/21/2021 diff --git a/aspnetcore/diagnostics/asp0007.md b/aspnetcore/diagnostics/asp0007.md index 2efc51a3a1..06013021a4 100644 --- a/aspnetcore/diagnostics/asp0007.md +++ b/aspnetcore/diagnostics/asp0007.md @@ -1,7 +1,7 @@ --- title: "ASP0007: Route parameter and argument optionality is mismatched" description: "Learn about analysis rule ASP0007: Route parameter and argument optionality is mismatched" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.date: 10/21/2021 diff --git a/aspnetcore/diagnostics/asp0008.md b/aspnetcore/diagnostics/asp0008.md index c7b1ff398c..0a571bcde2 100644 --- a/aspnetcore/diagnostics/asp0008.md +++ b/aspnetcore/diagnostics/asp0008.md @@ -1,9 +1,9 @@ --- title: "ASP0008: Do not use ConfigureWebHost with WebApplicationBuilder.Host" description: "Learn about analysis rule ASP0008: Do not use ConfigureWebHost with WebApplicationBuilder.Host" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-7.0' -ms.author: captainsafia +ms.author: safia ms.date: 09/23/2022 uid: diagnostics/asp0008 --- diff --git a/aspnetcore/diagnostics/asp0009.md b/aspnetcore/diagnostics/asp0009.md index 5742d4eb60..a66e4058ee 100644 --- a/aspnetcore/diagnostics/asp0009.md +++ b/aspnetcore/diagnostics/asp0009.md @@ -1,9 +1,9 @@ --- title: "ASP0009: Do not use Configure with WebApplicationBuilder.WebHost" description: "Learn about analysis rule ASP0009: Do not use Configure with WebApplicationBuilder.WebHost" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-7.0' -ms.author: captainsafia +ms.author: safia ms.date: 09/23/2022 uid: diagnostics/asp0009 --- diff --git a/aspnetcore/diagnostics/asp0010.md b/aspnetcore/diagnostics/asp0010.md index 0fb556bedf..fec73831e2 100644 --- a/aspnetcore/diagnostics/asp0010.md +++ b/aspnetcore/diagnostics/asp0010.md @@ -1,9 +1,9 @@ --- title: "ASP0010: Do not use UseStartup with WebApplicationBuilder.WebHost" description: "Learn about analysis rule ASP0010: Do not use UseStartup with WebApplicationBuilder.WebHost" -author: captainsafia +author: safia monikerRange: '>= aspnetcore-7.0' -ms.author: captainsafia +ms.author: safia ms.date: 09/23/2022 uid: diagnostics/asp0010 --- diff --git a/aspnetcore/diagnostics/asp0011.md b/aspnetcore/diagnostics/asp0011.md new file mode 100644 index 0000000000..736dc57fc5 --- /dev/null +++ b/aspnetcore/diagnostics/asp0011.md @@ -0,0 +1,55 @@ +--- +title: "ASP0011: Suggest using builder.Logging over Host.ConfigureLogging or WebHost.ConfigureLogging" +description: "Learn about analysis rule ASP0011: Suggest using builder.Logging over Host.ConfigureLogging or WebHost.ConfigureLogging" +author: safia +monikerRange: '>= aspnetcore-7.0' +ms.author: safia +ms.date: 09/27/2022 +uid: diagnostics/asp0011 +--- +# ASP0011: Suggest using builder.Logging over Host.ConfigureLogging or WebHost.ConfigureLogging + +| | Value | +|-|-| +| **Rule ID** |ASP0011| +| **Category** |Usage| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +`ConfigureLogging` isn't the recommended strategy for configuring logging in a minimal API application. + +## Rule description + +`ConfigureLogging` isn't the recommended strategy for configuring logging in a minimal API application. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Host.ConfigureLogging(logging => +{ + logging.AddJsonConsole(); +}) + +var app = builder.Build(); + +app.Run(); +``` + +## How to fix violations + +To fix a violation of this rule, use the `Logging` property on the `WebApplicationBuilder` to modify the logging configuration directly without the need for an additional `ConfigureLogging` call. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Logging.AddJsonConsole(); + +var app = builder.Build(); + +app.Run(); +``` + +## When to suppress warnings + +Do ***not*** suppress a warning from this rule. diff --git a/aspnetcore/diagnostics/asp0012.md b/aspnetcore/diagnostics/asp0012.md new file mode 100644 index 0000000000..bda28f405d --- /dev/null +++ b/aspnetcore/diagnostics/asp0012.md @@ -0,0 +1,55 @@ +--- +title: "ASP0012: Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices" +description: "Learn about analysis rule ASP0012: Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices" +author: safia +monikerRange: '>= aspnetcore-7.0' +ms.author: safia +ms.date: 09/27/2022 +uid: diagnostics/asp0012 +--- +# ASP0012: Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices + +| | Value | +|-|-| +| **Rule ID** |ASP0012| +| **Category** |Usage| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +`ConfigureServices` isn't the recommended strategy for registering services in DI in a minimal API application. + +## Rule description + +`ConfigureServices` isn't the recommended strategy for configuring logging in a minimal API application. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Host.ConfigureServices(services => +{ + services.AddAntiforgery(); +}) + +var app = builder.Build(); + +app.Run(); +``` + +## How to fix violations + +To fix a violation of this rule, use the `Services` property on the `WebApplicationBuilder` to modify the DI container directly without the need for an additional `ConfigureServices` call. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddAntiforgery(); + +var app = builder.Build(); + +app.Run(); +``` + +## When to suppress warnings + +Do ***not*** suppress a warning from this rule. diff --git a/aspnetcore/diagnostics/asp0013.md b/aspnetcore/diagnostics/asp0013.md new file mode 100644 index 0000000000..457fb79294 --- /dev/null +++ b/aspnetcore/diagnostics/asp0013.md @@ -0,0 +1,55 @@ +--- +title: "ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration" +description: "Learn about analysis rule ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration" +author: safia +monikerRange: '>= aspnetcore-7.0' +ms.author: safia +ms.date: 09/27/2022 +uid: diagnostics/asp0013 +--- +# ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration + +| | Value | +|-|-| +| **Rule ID** |ASP0013| +| **Category** |Usage| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +`Configure` isn't the recommended strategy for reading and writing to configuration in a minimal API application. + +## Rule description + +`Configure` isn't the recommended strategy for configuring logging in a minimal API application. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Host.ConfigureAppConfiguration(builder => +{ + builder.AddJsonFile("customAppSettings.json"); +}) + +var app = builder.Build(); + +app.Run(); +``` + +## How to fix violations + +To fix a violation of this rule, use the `Configuration` property on the `WebApplicationBuilder` to modify application configuration directly without the need for an additional `ConfigureAppConfiguration` call. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +builder.Configuration..AddJsonFile("customAppSettings.json"); + +var app = builder.Build(); + +app.Run(); +``` + +## When to suppress warnings + +Do ***not*** suppress a warning from this rule. diff --git a/aspnetcore/diagnostics/asp0014.md b/aspnetcore/diagnostics/asp0014.md new file mode 100644 index 0000000000..ccd9f1a67d --- /dev/null +++ b/aspnetcore/diagnostics/asp0014.md @@ -0,0 +1,54 @@ +--- +title: "ASP0014: Suggest using top level route registrations" +description: "Learn about analysis rule ASP0014: Suggest using top level route registrations" +author: safia +monikerRange: '>= aspnetcore-7.0' +ms.author: safia +ms.date: 09/27/2022 +uid: diagnostics/asp0014 +--- +# ASP0014: Suggest using top level route registrations +| | Value | +|-|-| +| **Rule ID** |ASP0014| +| **Category** |Usage| +| **Fix is breaking or non-breaking** |Non-breaking| + +## Cause + +Routes can be registered directly at the top-level of a minimal API application. + +## Rule description + +Routes can be registered directly at the top-level of a minimal API application and don't need to be nested within a `UseEndpoints` call. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +var app = builder.Build(); + +app.UseEndpoints(endpoints => +{ + endpoints.MapGet("/", () => "Hello World!"); +}); + +app.Run(); +``` + +## How to fix violations + +To fix a violation of this rule, register the endpoints directly on the `WebApplication`. + +```csharp +var builder = WebApplication.CreateBuilder(args); + +var app = builder.Build(); + +app.MapGet("/", () => "Hello World!"); + +app.Run(); +``` + +## When to suppress warnings + +Do ***not*** suppress a warning from this rule. diff --git a/aspnetcore/diagnostics/code-analysis.md b/aspnetcore/diagnostics/code-analysis.md index 31f498bb87..7b25368f0f 100644 --- a/aspnetcore/diagnostics/code-analysis.md +++ b/aspnetcore/diagnostics/code-analysis.md @@ -23,6 +23,10 @@ uid: diagnostics/code-analysis | [ASP0008](xref:diagnostics/asp0008) | Non-breaking | Do not use ConfigureWebHost with WebApplicationBuilder.Host | | [ASP0009](xref:diagnostics/asp0009) | Non-breaking | Do not use Configure with WebApplicationBuilder.WebHost | | [ASP0010](xref:diagnostics/asp0010) | Non-breaking | Do not use UseStartup with WebApplicationBuilder.WebHost | +| [ASP0011](xref:diagnostics/asp0011) | Non-breaking | Suggest using builder.Logging over Host.ConfigureLogging or WebHost.ConfigureLogging | +| [ASP0012](xref:diagnostics/asp0012) | Non-breaking | Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices | +| [ASP0013](xref:diagnostics/asp0013) | Non-breaking | Suggest switching from using Configure methods to WebApplicationBuilder.Configuration | +| [ASP0014](xref:diagnostics/asp0014) | Non-breaking | Suggest using top level route registrations | | [BL0001](xref:diagnostics/bl0001) | Breaking | Component parameter should have public setters | | [BL0002](xref:diagnostics/bl0002) | Non-breaking | Component has multiple CaptureUnmatchedValues parameters | | [BL0003](xref:diagnostics/bl0003) | Breaking | Component parameter with CaptureUnmatchedValues has the wrong type |