-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Analyzer] : Warn when registering custom IProblemDetailsWriter after calling AddRazorPages, etc #48180
Comments
Thanks for contacting us. We're moving this issue to the |
We could add this new analyzer to the |
Here's a simple suggestion for the title and message of the new diagnostic: Title: Custom IProblemDetailsWriter is incorrectly configured |
I'd be happy to put up a PR for this once the API for the new diagnostic is approved. |
We'll want to report this diagnostic for |
API for proposed analyzerDiagnostic:Title: Custom IProblemDetailsWriter is incorrectly configured Context:If a custom IProblemDetailsWriter is registered after a MvcServiceCollectionExtensions method, the DefaultProblemDetailsWriter will be used rather of the custom IProblemDetailsWriter. This analyzer would report 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). Example Usage:Diagnostic Reported: services.AddControllers();
// Diagnostic reported on method invocation below
services.AddTransient<IProblemDetailsWriter, SampleProblemDetailsWriter>(); No Diagnostic Reported: services.AddTransient<IProblemDetailsWriter, SampleProblemDetailsWriter>();
services.AddControllers(); |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
While all the runtime ideas seem good, it doesn't negate the fact that the analyzer would also be helpful. API Approved!
|
@halter73 I can add a code fix for moving the |
Thanks for offering to do the code fix @david-acker! New analyzers should go into We prefer that over the legacy Microsoft.AspNetCore.Analyzers project in |
Sounds good! I'll move the new analyzer over to Do we want to clone some of the |
Background and Motivation
Registering a custom
IProblemDetailsWriter
after callingAddRazorPages
, etc results in theDefaultProblemDetailsWriter
, not the customIProblemDetailsWriter
being called.Proposed Analyzer
Analyzer Behavior and Message
Issue a warning when Registering a custom
IProblemDetailsWriter
after callingAddRazorPages
, etc.ASP0001: Authorization middleware is incorrectly configured is similar.
See dotnet/AspNetCore.Docs#29152
Note: When using a custom
IProblemDetailsWriter
, the customIProblemDetailsWriter
must be registered before calling AddRazorPages, AddControllers, or AddControllersWithViews.Category
Severity Level
Usage Scenarios
Issue a warning when Registering a custom
IProblemDetailsWriter
after callingAddRazorPages
, etc.Risks
None.
The text was updated successfully, but these errors were encountered: