Open
Description
Background and Motivation
Proposed Analyzer
For middlesware that are registered automatically by the WebApplication, consider a refactoring to manually add them back to the application.
Analyzer Behavior and Message
Category
- Design
- Documentation
- Globalization
- Interoperability
- Maintainability
- Naming
- Performance
- Reliability
- Security
- Style
- Usage
Severity Level
- Error
- Warning
- Info
- Hidden
Usage Scenarios
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build(); // <-- underline 'app' with refactor suggestion
app.Run();
var app = WebApplication.Create(args); // <-- underline 'app' with refactor suggestion
app.Run();
Result:
var app = WebApplication.Create(args);
if (app.HostingEnvironment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthentication(); // detect any `UseAuthentication` call and omit this if there is one
app.UseAuthorization(); // detect any `UseAuthorization` call and omit this if there is one
// additionally, place after any existing `UseAuthentication` call
// detect user middleware/endpoints and put them here
app.UseEndpoints(e => {});
app.Run();
Risks
We will not be able to place the auto-injected middleware correctly in all situations, that should be fine since this refactor is to help users be explicit about their middleware order.
Another risk is if we add more implicit middleware we'll want to keep the refactoring up to date.