Add docs for analyzers ASP0011-14 (#27109)

* Add docs for analyzers ASP0011-14

* captainsafia => safia

* Apply suggestions from code review

Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>

Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
pull/27112/head
Safia Abdalla 2022-09-27 16:52:40 -07:00 committed by GitHub
parent 1eb1c97f4a
commit 70a38d71e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 234 additions and 11 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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