-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update IResult implementation to support TypedResults properly (#68)
* Update IResult implementation to support TypedResults properly Fixes #64 * Delete IRazorSliceHttpResult.cs * Update IResultExtensions.cs
- Loading branch information
1 parent
d5e7d7a
commit d0bb85f
Showing
6 changed files
with
37 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,28 @@ | ||
using System.Text.Encodings.Web; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Http.HttpResults; | ||
|
||
namespace RazorSlices; | ||
|
||
internal sealed class RazorSliceHttpResultWrapper(RazorSlice razorSlice) : IRazorSliceHttpResult, IDisposable | ||
internal sealed class RazorSliceHttpResultWrapper(RazorSlice razorSlice) : RazorSliceHttpResult, IResult | ||
{ | ||
public int? StatusCode { get; set; } = StatusCodes.Status200OK; | ||
|
||
int? IStatusCodeHttpResult.StatusCode => StatusCode; | ||
|
||
public string ContentType => "text/html; charset=utf-8"; | ||
|
||
public HtmlEncoder? HtmlEncoder { get; set; } | ||
public override Task ExecuteAsync() => razorSlice.ExecuteAsync(); | ||
|
||
/// <inheritdoc /> | ||
Task IResult.ExecuteAsync(HttpContext httpContext) | ||
{ | ||
razorSlice.HttpContext = httpContext; | ||
return RazorSliceHttpResultHelpers.ExecuteAsync(razorSlice, httpContext, HtmlEncoder, StatusCode ?? StatusCodes.Status200OK, ContentType); | ||
return RazorSliceHttpResultHelpers.ExecuteAsync(razorSlice, httpContext, HtmlEncoder, StatusCode, ContentType); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
internal sealed class RazorSliceHttpResultWrapper<TModel>(RazorSlice<TModel> razorSlice) : RazorSliceHttpResult<TModel>, IResult | ||
{ | ||
public override Task ExecuteAsync() => razorSlice.ExecuteAsync(); | ||
|
||
/// <inheritdoc /> | ||
Task IResult.ExecuteAsync(HttpContext httpContext) | ||
{ | ||
razorSlice.Dispose(); | ||
razorSlice.HttpContext = httpContext; | ||
return RazorSliceHttpResultHelpers.ExecuteAsync(razorSlice, httpContext, HtmlEncoder, StatusCode, ContentType); | ||
} | ||
} |