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

Class ValueObjectMessageOptions

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

Where a refused value object finds a message in the application's language: a resource read through IStringLocalizerFactory, under the key of the rule's code.

public sealed class ValueObjectMessageOptions

Inheritance​

object ← ValueObjectMessageOptions

Inherited Members​

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

Remarks​

The options of WithValueObjectProblemDetails(messages => …) on a minimal API, of AddValueObjects(messages => …) on MVC, and of UseValueObjectProblemDetails(messages => …) on an Azure Functions HTTP trigger. Without a resource, a refusal keeps the English message of the rule. With one, the message is looked up under the keys of : the key of the code, ValueObject.value_object.too_short, after the same key followed by .minimum or .maximum for a range of one bound. It is formatted with the member the refusal is listed under as {0}, followed by the arguments reads from the type's rules, from {1}. A key with no entry keeps the English message.

The current UI culture chooses the resource, and the current culture formats the arguments: with UseRequestLocalization(), both follow the request. An Azure Functions invocation runs on the host's call, not on the request's, so the Functions middleware applies the request's cultures itself: those UseRequestLocalization() chose, or else those the application's RequestLocalizationOptions choose from the request. The localizer comes from the request's services, which builder.Services.AddLocalization() registers; without it, a refusal throws an naming the call. A template quoting an argument its code does not supply is the application's error, and its is not caught.

The type lives in AdCodicem.ValueObjects.AspNetCore.Http, beside and under the same namespace, so that the minimal API package, the MVC one and the Azure Functions ASP.NET Core one, which reference it, share it.

Properties​

ResourceType​

Gets the type whose resources hold the messages, or null to keep the English messages.

public Type? ResourceType { get; }

Property Value​

Type?

Methods​

UseResource<TResource>()​

Reads the messages from the resources of TResource.

public ValueObjectMessageOptions UseResource<TResource>()

Returns​

ValueObjectMessageOptions

These options, so calls can be chained.

Type Parameters​

TResource

The type the resources are named after, as IStringLocalizer<T> names them: an empty class of the application, beside a .resx file of the same name for each culture.

UseResource(Type)​

Reads the messages from the resources of a type.

public ValueObjectMessageOptions UseResource(Type resourceType)

Parameters​

resourceType Type

The type the resources are named after.

Returns​

ValueObjectMessageOptions

These options, so calls can be chained.

Exceptions​

ArgumentNullException

resourceType is null.