Skip to content

Commit

Permalink
Add XML comments to DefaultProblemDetailsFactory.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniBraconi committed May 15, 2024
1 parent c60f195 commit 9671a96
Showing 1 changed file with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,37 @@
using Microsoft.Extensions.Options;

namespace Microsoft.AspNetCore.Mvc.Infrastructure;

/// <summary>
/// The `DefaultProblemDetailsFactory` is a concrete implementation of the `ProblemDetailsFactory` abstract class.
/// It provides methods to create instances of `ProblemDetails` and `ValidationProblemDetails` with default settings.
/// This class uses the provided `ApiBehaviorOptions` for client error mapping and an optional custom configuration action to further customize the problem details.
/// </summary>
public sealed class DefaultProblemDetailsFactory : ProblemDetailsFactory
{
private readonly ApiBehaviorOptions _options;
private readonly Action<ProblemDetailsContext>? _configure;

/// <summary>
/// Initializes a new instance of the <see cref="DefaultProblemDetailsFactory"/> class.
/// </summary>
/// <param name="options">The options for API behavior.</param>
/// <param name="problemDetailsOptions">The options for customizing problem details.</param>
public DefaultProblemDetailsFactory(
IOptions<ApiBehaviorOptions> options,
IOptions<ProblemDetailsOptions>? problemDetailsOptions = null)
{
_options = options?.Value ?? throw new ArgumentNullException(nameof(options));
_configure = problemDetailsOptions?.Value?.CustomizeProblemDetails;
}

/// <summary>
/// Creates a new instance of the <see cref="ProblemDetails"/> class with the specified parameters.
/// </summary>
/// <param name="httpContext">The HTTP context.</param>
/// <param name="statusCode">The status code.</param>
/// <param name="title">The title.</param>
/// <param name="type">The type.</param>
/// <param name="detail">The detail.</param>
/// <param name="instance">The instance.</param>
/// <returns>A new instance of the <see cref="ProblemDetails"/> class.</returns>
public override ProblemDetails CreateProblemDetails(
HttpContext httpContext,
int? statusCode = null,
Expand All @@ -46,7 +63,18 @@ public override ProblemDetails CreateProblemDetails(

return problemDetails;
}

/// <summary>
/// Creates a new instance of the <see cref="ValidationProblemDetails"/> class with the specified parameters.
/// This method uses the provided ModelStateDictionary to initialize the ValidationProblemDetails instance.
/// </summary>
/// <param name="httpContext">The HTTP context.</param>
/// <param name="modelStateDictionary">The ModelStateDictionary containing the validation errors.</param>
/// <param name="statusCode">The status code. Defaults to 400 if not provided.</param>
/// <param name="title">The title.</param>
/// <param name="type">The type.</param>
/// <param name="detail">The detail.</param>
/// <param name="instance">The instance.</param>
/// <returns>A new instance of the <see cref="ValidationProblemDetails"/> class.</returns>
public override ValidationProblemDetails CreateValidationProblemDetails(
HttpContext httpContext,
ModelStateDictionary modelStateDictionary,
Expand Down

0 comments on commit 9671a96

Please sign in to comment.