dotnet / dotnet/aspnetcore

[Analyzer] Detect adding middleware services but middleware isn't used

Open
#44,243 6 comments 0 reactions 0 assignees View on GitHub
analyzer area-middleware area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Developers can add the services for middleware, e.g. `AddCors`, and not realize that the middleware needs to be registered in middleware with `UseCors`. There is no error or indication to the developer about what they're missing.

### Describe the solution you'd like

An analyzer that looks at what middleware services are registered, what middleware is used in request pipeline, and warns the developer about middleware that's unused.

We can't infer what these names are so we'd hard code AddMiddleware and UseMiddleware method names.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.