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
Add a AddDefaultProblemDetailsFactory method that allows registering the internal DefaultProblemDetailsFactory
class with the container
#53030
Comments
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:
API Approved! namespace Microsoft.AspNetCore.Mvc.Infrastructure;
- internal sealed class DefaultProblemDetailsFactory : ProblemDetailsFactory
+ public sealed class DefaultProblemDetailsFactory : ProblemDetailsFactory
{
+ public DefaultProblemDetailsFactory(IOptions<ApiBehaviorOptions> options, IOptions<ProblemDetailsOptions>? problemDetailsOptions = null);
+ public override ProblemDetails CreateProblemDetails(HttpContext httpContext, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null);
+ public override ValidationProblemDetails CreateValidationProblemDetails(HttpContext httpContext, ModelStateDictionary modelStateDictionary, int? statusCode = null, string? title = null, string? type = null, string? detail = null, string? instance = null);
} |
Awesome; making the type public was my first suggestion in the discussion thread, so this works for me. Should I plan to wait until .NET 9 to see this change, or can this be released before? |
Sticking this in the backlog for now since it is low-pri. However, I'd be happy to review a PR for this given that the API has already been approved. Marking as |
Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the |
Background and Motivation
Quote from #49982:
On top of that, the proposed API will bring the two Problem Details spaces one tiny step closer and more unified without introducing any breaking changes.
Proposed API
The proposed API is to add a new
AddDefaultProblemDetailsFactory
extension method that registers the defaultDefaultProblemDetailsFactory
class and update theAddMvcCore
method to leverage that extension instead.Since the
Microsoft.AspNetCore.Http
abstractions seem like a better place than MVC to consolidate Problem Details classes, I suggest adding the extension method there if possible. The suggestedAddDefaultProblemDetailsFactory
method would look like this:Update to MVC
AddMvcCoreServices
method:See the MvcCoreServiceCollectionExtensions class.
In case the team wants to consolidate the optional dependency from the preceding code blocks, they could also consider adapting the
AddProblemDetails
method of theProblemDetailsServiceCollectionExtensions
class to use this extension as well:Of course, doing what the preceding code block suggests would add an additional dependency not used by the
ProblemDetailsService
class (theProblemDetailsFactory
) but would centralize the registering of the defaultIProblemDetailsWriter
, which would guarantee that both MVC and Minimal APIs are aligned in their default implementation.Usage Examples
One could register the factory like this (
Program.cs
):Alternative Designs
Please refer to the following issue for more info about alternate designs and thoughts put into this proposal in conjunction with @captainsafia: #49982.
Risks
No foreseeable risks.
The text was updated successfully, but these errors were encountered: