Table of Contents

Class WriteOutcomeExtensions

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Maps WriteOutcome<T> to ActionResult/IResult with correct status codes and headers.

public static class WriteOutcomeExtensions
Inheritance
WriteOutcomeExtensions
Inherited Members

Methods

ToActionResult<T, TOut>(WriteOutcome<T>, ControllerBase, Func<T, TOut>?)

Converts a WriteOutcome<T> to an ActionResult with correct HTTP status codes and headers, honoring the RFC 7240 Prefer request header.

public static ActionResult ToActionResult<T, TOut>(this WriteOutcome<T> outcome, ControllerBase controller, Func<T, TOut>? map = null)

Parameters

outcome WriteOutcome<T>
controller ControllerBase
map Func<T, TOut>

Returns

ActionResult

Type Parameters

T
TOut

Remarks

When the Prefer: return=minimal header is present and the outcome is WriteOutcome<T>.Updated, returns 204 No Content instead of 200 OK with body. When Prefer: return=representation is present, returns 200 OK with body (the default behavior for Updated).

The Preference-Applied response header is emitted when a return preference is honored. Other outcomes (WriteOutcome<T>.Created, WriteOutcome<T>.UpdatedNoContent, WriteOutcome<T>.Accepted, WriteOutcome<T>.AcceptedNoContent) are not affected by the return preference.

ToHttpResult<T>(WriteOutcome<T>, HttpContext)

Converts a WriteOutcome<T> to a Minimal API IResult with correct HTTP status codes and headers, honoring the RFC 7240 Prefer request header. The domain value is serialized directly without transformation.

public static IResult ToHttpResult<T>(this WriteOutcome<T> outcome, HttpContext httpContext)

Parameters

outcome WriteOutcome<T>

The write outcome to convert.

httpContext HttpContext

The HTTP context (used to read Prefer header and set response headers).

Returns

IResult

An IResult with appropriate status code, headers, and optional body.

Type Parameters

T

The domain type contained in the outcome.

ToHttpResult<T, TOut>(WriteOutcome<T>, HttpContext, Func<T, TOut>?)

Converts a WriteOutcome<T> to a Minimal API IResult with correct HTTP status codes and headers, honoring the RFC 7240 Prefer request header.

public static IResult ToHttpResult<T, TOut>(this WriteOutcome<T> outcome, HttpContext httpContext, Func<T, TOut>? map)

Parameters

outcome WriteOutcome<T>

The write outcome to convert.

httpContext HttpContext

The HTTP context (used to read Prefer header and set response headers).

map Func<T, TOut>

Function to transform the domain value to a response DTO.

Returns

IResult

An IResult with appropriate status code, headers, and optional body.

Type Parameters

T

The domain type contained in the outcome.

TOut

The mapped output type for the response body.

Remarks

When the Prefer: return=minimal header is present and the outcome is WriteOutcome<T>.Updated, returns 204 No Content instead of 200 OK with body. When Prefer: return=representation is present, returns 200 OK with body (the default behavior for Updated).

The Preference-Applied response header is emitted when a return preference is honored. Other outcomes (WriteOutcome<T>.Created, WriteOutcome<T>.UpdatedNoContent, WriteOutcome<T>.Accepted, WriteOutcome<T>.AcceptedNoContent) are not affected by the return preference.

ToUpdatedActionResultAsync<TIn, TOut>(Task<Result<TIn>>, ControllerBase, Func<TIn, RepresentationMetadata>, Func<TIn, TOut>)

public static Task<ActionResult<TOut>> ToUpdatedActionResultAsync<TIn, TOut>(this Task<Result<TIn>> resultTask, ControllerBase controller, Func<TIn, RepresentationMetadata> metadataSelector, Func<TIn, TOut> map)

Parameters

resultTask Task<Result<TIn>>
controller ControllerBase
metadataSelector Func<TIn, RepresentationMetadata>
map Func<TIn, TOut>

Returns

Task<ActionResult<TOut>>

Type Parameters

TIn
TOut

ToUpdatedActionResultAsync<TIn, TOut>(ValueTask<Result<TIn>>, ControllerBase, Func<TIn, RepresentationMetadata>, Func<TIn, TOut>)

public static ValueTask<ActionResult<TOut>> ToUpdatedActionResultAsync<TIn, TOut>(this ValueTask<Result<TIn>> resultTask, ControllerBase controller, Func<TIn, RepresentationMetadata> metadataSelector, Func<TIn, TOut> map)

Parameters

resultTask ValueTask<Result<TIn>>
controller ControllerBase
metadataSelector Func<TIn, RepresentationMetadata>
map Func<TIn, TOut>

Returns

ValueTask<ActionResult<TOut>>

Type Parameters

TIn
TOut

ToUpdatedActionResult<TIn, TOut>(Result<TIn>, ControllerBase, Func<TIn, RepresentationMetadata>, Func<TIn, TOut>)

Converts a successful Result<TValue> to an updated response with dynamic metadata, honoring RFC 7240 Prefer.

public static ActionResult<TOut> ToUpdatedActionResult<TIn, TOut>(this Result<TIn> result, ControllerBase controller, Func<TIn, RepresentationMetadata> metadataSelector, Func<TIn, TOut> map)

Parameters

result Result<TIn>

The result from the update operation.

controller ControllerBase

The controller context.

metadataSelector Func<TIn, RepresentationMetadata>

Function to build metadata from the domain value (e.g., extract ETag).

map Func<TIn, TOut>

Function to transform the domain value to a response DTO.

Returns

ActionResult<TOut>

An ActionResult with appropriate status code and headers.

Type Parameters

TIn

The domain type in the result.

TOut

The mapped output type for the response body.

ToUpdatedActionResult<TIn, TOut>(Result<TIn>, ControllerBase, RepresentationMetadata?, Func<TIn, TOut>)

Converts a successful Result<TValue> to an updated response, honoring RFC 7240 Prefer. Returns 200 OK with body by default, or 204 No Content when Prefer: return=minimal is present. On failure, returns the appropriate error response.

public static ActionResult<TOut> ToUpdatedActionResult<TIn, TOut>(this Result<TIn> result, ControllerBase controller, RepresentationMetadata? metadata, Func<TIn, TOut> map)

Parameters

result Result<TIn>

The result from the update operation.

controller ControllerBase

The controller context.

metadata RepresentationMetadata

Optional representation metadata (ETag, Last-Modified, etc.).

map Func<TIn, TOut>

Function to transform the domain value to a response DTO.

Returns

ActionResult<TOut>

An ActionResult with appropriate status code and headers.

Type Parameters

TIn

The domain type in the result.

TOut

The mapped output type for the response body.