Class WriteOutcomeExtensions
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
outcomeWriteOutcome<T>controllerControllerBasemapFunc<T, TOut>
Returns
Type Parameters
TTOut
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
outcomeWriteOutcome<T>The write outcome to convert.
httpContextHttpContextThe HTTP context (used to read Prefer header and set response headers).
Returns
Type Parameters
TThe 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
outcomeWriteOutcome<T>The write outcome to convert.
httpContextHttpContextThe HTTP context (used to read Prefer header and set response headers).
mapFunc<T, TOut>Function to transform the domain value to a response DTO.
Returns
Type Parameters
TThe domain type contained in the outcome.
TOutThe 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>)
Async Task variant of ToUpdatedActionResult<TIn, TOut>(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
resultTaskTask<Result<TIn>>controllerControllerBasemetadataSelectorFunc<TIn, RepresentationMetadata>mapFunc<TIn, TOut>
Returns
- Task<ActionResult<TOut>>
Type Parameters
TInTOut
ToUpdatedActionResultAsync<TIn, TOut>(ValueTask<Result<TIn>>, ControllerBase, Func<TIn, RepresentationMetadata>, Func<TIn, TOut>)
Async ValueTask variant of ToUpdatedActionResult<TIn, TOut>(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
resultTaskValueTask<Result<TIn>>controllerControllerBasemetadataSelectorFunc<TIn, RepresentationMetadata>mapFunc<TIn, TOut>
Returns
- ValueTask<ActionResult<TOut>>
Type Parameters
TInTOut
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
resultResult<TIn>The result from the update operation.
controllerControllerBaseThe controller context.
metadataSelectorFunc<TIn, RepresentationMetadata>Function to build metadata from the domain value (e.g., extract ETag).
mapFunc<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
TInThe domain type in the result.
TOutThe 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
resultResult<TIn>The result from the update operation.
controllerControllerBaseThe controller context.
metadataRepresentationMetadataOptional representation metadata (ETag, Last-Modified, etc.).
mapFunc<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
TInThe domain type in the result.
TOutThe mapped output type for the response body.