Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectHttpServiceCollectionExtensions

Namespace: AdCodicem.ValueObjects.AspNetCore.Http
Assembly: AdCodicem.ValueObjects.AspNetCore.Http.dll

Registers what answers a value object a minimal API could not bind when the binder throws instead of answering.

public static class ValueObjectHttpServiceCollectionExtensions

Inheritance​

object ← ValueObjectHttpServiceCollectionExtensions

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Methods​

AddValueObjectHttpProblemDetails(IServiceCollection)​

Registers the exception handler that answers a refused value object with problem details carrying the code of its rule when RouteHandlerOptions.ThrowOnBadRequest is on.

public static IServiceCollection AddValueObjectHttpProblemDetails(this IServiceCollection services)

Parameters​

services IServiceCollection

The application's services.

Returns​

IServiceCollection

The same services, so calls can be chained.

Remarks​

With ThrowOnBadRequest on, the default in Development, a minimal API throws a where it would answer a bare 400, before any endpoint filter runs. The handler takes that exception, on an endpoint covered by alone, and answers 400 with the problem details the filter writes: the route, query and header values of the endpoint parsed again, and the value object a request body refused, under its JSON path, with the code reads from the exception the serializer threw. It never copies the framework's message, which names the refused text; a key a dictionary keyed by a value object refuses is listed under its JSON path, which holds the key, as MVC lists it. Any other exception, a 400 no value object caused among them, is left to the next handler, a body the serializer cannot read at all included, even beside a refused route, query or header value: with ThrowOnBadRequest off, the framework answers such a body before any filter runs, and the handler keeps that answer. On an endpoint whose convention names a resource of messages, the handler answers with them, in the culture of the request, whatever the order of UseRequestLocalization() and UseExceptionHandler().

It is an , which the exception handler middleware calls: register AddProblemDetails() and call app.UseExceptionHandler() wherever ThrowOnBadRequest is on. Handlers run in the order they were registered, so register it before a handler that answers every exception. Registering it twice registers it once.

Exceptions​

ArgumentNullException

services is null.