You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the API methods have to call .ToActionResult() / .ToResult() extension methods for converting a DomainResult to IActionResult/IResult.
To avoid the repetitive calls of those methods, the MVC package can offer filters (IResultFilter for the classic controllers and IEndpointFilter for the minimal API). So, if the returning type is DomainResultBase or Task<DomainResultBase>', it would
call .ToActionResult() or .ToActionResultOfT() for the classic controllers;
call .ToResult() or .ToResultOfT() for the minimal API.
After some preliminary research, the idea seems viable but has some downsides.
Experiment
In my research, I created a test filter:
publicclassActionFilter:IActionFilter,IEndpointFilter{publicvoidOnActionExecuted(ActionExecutedContextcontext){varactionResult=(context.ResultasObjectResult)?.Value;if(actionResultisIDomainResultresult)context.Result=result.ToActionResult();// ... Other types are harder to handle}publicasyncValueTask<object?>InvokeAsync(EndpointFilterInvocationContextcontext,EndpointFilterDelegatenext){// See context herereturnawaitnext(context);}}
which was registered globally for the classic API as
The classic controllers would have to step away from the usual strongly typed returned signature (e.g.IActionResult,ActionResult<T>) in favour of IDomainResult or IDomainResult<T>. Hence, it'll likely cause integration issues (e.g. with Swagger docs). Example:
For the Minimal API, it seems that a globally registered filter for all routes is not an option. Hence, a piped call would be required (not much different from explicitly calling an extension method on IDomainResult). Though, depending on how the routes are added, the filter call can be consolidated in one place. Example:
Currently, the API methods have to call
.ToActionResult()
/.ToResult()
extension methods for converting aDomainResult
toIActionResult
/IResult
.To avoid the repetitive calls of those methods, the MVC package can offer filters (
IResultFilter
for the classic controllers andIEndpointFilter
for the minimal API). So, if the returning type isDomainResultBase
orTask<DomainResultBase>
', it would.ToActionResult()
or.ToActionResultOfT()
for the classic controllers;.ToResult()
or.ToResultOfT()
for the minimal API.Notes:
ToCustomActionResultOfT()
is used, the filters wouldn't helpThe text was updated successfully, but these errors were encountered: