[Analyzer] Detect adding middleware services but middleware isn't used
See original GitHub issueIs there an existing issue for this?
- 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
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
[Analyzer] Detect middleware in pipeline after terminal ...
(maybe) Detect terminal middleware with WebApplication . Warn the developer they may need to add UseEndpoints before terminal middleware.
Read more >c# - Confirm that middleware is in use
I am trying to confirm via a unit test that middleware is actually being added to the pipeline. I have the following static...
Read more >ASP.NET Core Middleware
Learn about ASP.NET Core middleware and the request pipeline. ... Middleware code analysis; Create a middleware pipeline with WebApplication ...
Read more >Understanding your middleware pipeline with the ...
Analysing your middleware pipeline · 1. Add the required packages · 2. Creating a diagnostic adapter · 3. Add the necessary services.
Read more >ASP.NET Core middleware with Roslyn Analyzers - Part 1
Learn how to create Roslyn Analyzers to help add ASP.NET Core middleware in the right order. In this post, I'll show you how...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes this is the only analyzer suggestion I think shouldn’t be a warning by default. People will refactor things into methods and the analyzer will get confused quickly.
Thanks for contacting us.
We’re moving this issue to the
.NET 8 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.