Class ValueObjectProblemDetails
Namespace: AdCodicem.ValueObjects.AspNetCore
Assembly: AdCodicem.ValueObjects.AspNetCore.Http.dll
Names the problem details member that maps each rejected member to the code of the rule it broke, and carries the violated rule from the MVC model binder to the problem details response.
public static class ValueObjectProblemDetails
Inheritance
object ← ValueObjectProblemDetails
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
ModelStateDictionary only holds a message, and a message is not something a client can branch on. The
stable error code rides alongside it on the request, and AddValueObjectProblemDetails() on
ApiBehaviorOptions, in AdCodicem.ValueObjects.AspNetCore, folds it into the RFC 9457 body as an
errorCodes extension. A minimal API endpoint covered by
UseValueObjectProblemDetails().
The type lives in AdCodicem.ValueObjects.AspNetCore.Http, which every application on ASP.NET Core can
reference, native AOT included, and keeps its namespace: AdCodicem.ValueObjects.AspNetCore references that
package and forwards the type, so code compiled against either assembly finds it.
Fields
ExtensionName
The extension member added to the problem details body, mapping each rejected member to its error code.
public const string ExtensionName = "errorCodes"
Field Value
Methods
GetErrorCodes(HttpContext?)
Gets the codes recorded for the current request.
public static IReadOnlyDictionary<string, string> GetErrorCodes(HttpContext? httpContext)
Parameters
httpContext HttpContext?
Current request.
Returns
IReadOnlyDictionary<string, string>
The recorded codes, or an empty dictionary.
RecordErrorCode(HttpContext?, string, string)
Records the code of the rule a bound value violated.
public static void RecordErrorCode(HttpContext? httpContext, string memberName, string errorCode)
Parameters
httpContext HttpContext?
Current request.
memberName string
Name of the rejected model member.
errorCode string
Stable code of the violated rule.
Remarks
A member recorded again keeps its first code, the one beside the first of its errors: MVC binds every element of a query array under the array's name, and a JSON body may repeat a key, so a member can be refused more than once. A minimal API's problem details keep the first code the same way.