aspnetcore
aspnetcore copied to clipboard
Add analyzer for custom IProblemDetailsWriter registration
Add analyzer for custom IProblemDetailsWriter registration
Adds an analyzer that checks that custom IProblemDetailsWriters are registered in the correct order, relative to MvcServiceCollectionExtensions method calls.
Description
If a custom IProblemDetailsWriter is registered after a MvcServiceCollectionExtensions method, the DefaultProblemDetailsWriter will be used instead of the custom IProblemDetailsWriter.
This analyzer reports a warning level diagnostic when an IProblemDetailsWriter is registered (using AddTransient, AddScoped, or AddSingleton) and appears after a call to a MvcServiceCollectionExtensions method (AddControllers, AddControllersWithViews, AddMvc, or AddRazorPages).
Diagnostic
Id: ASP0026 Title: Custom IProblemDetailsWriter is incorrectly configured Message: The custom IProblemDetailsWriter must be registered before calling AddControllers, AddControllersWithViews, AddMvc, or AddRazorPages. Severity: Warning
Code Examples:
Diagnostic Reported:
services.AddControllers();
// Diagnostic reported on method invocation below
services.AddTransient<IProblemDetailsWriter, SampleProblemDetailsWriter>();
No Diagnostic Reported:
services.AddTransient<IProblemDetailsWriter, SampleProblemDetailsWriter>();
services.AddControllers();
Analyzer Infrastructure Changes
- Brings over
StartupAnalyzer-related infrastructure from the legacyMicrosoft.AspNetCore.Analyzersproject
Fixes #48180
Thanks for your PR, @david-acker. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.
@david-acker, Are you still working on this one? No pressure, just asking because it's been sitting in draft state for a while.
I'm planning on working on this again fairly soon now that the API has finally approved.
@captainsafia PTAL
/azp run
Azure Pipelines successfully started running 3 pipeline(s).
@david-acker I saw you posted a question in the original issue about moving StartupAnalyzer-related infrastructure to the analyzers that get shipped in the refpack. I'm in favor of incorproating a StartupAnalyzer in that project and using source-sharing to bring in helpful dependencies like StartupFacts.
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.