@@ -38,7 +38,7 @@ public static IEndpointRouteBuilder MapApiRoutes(this IEndpointRouteBuilder buil
38
38
return new NotFoundResult ( ) ;
39
39
}
40
40
41
- return new ObjectResult ( model ) as IResult ;
41
+ return new JsonResult ( model ) as IResult ;
42
42
} ) . RequireAuthorization ( ) ;
43
43
44
44
// Create a new Todo item
@@ -92,47 +92,28 @@ public static IEndpointRouteBuilder MapApiRoutes(this IEndpointRouteBuilder buil
92
92
return builder ;
93
93
}
94
94
95
- // HACK Custom result types until ObjectResult implements IResult.
95
+ // HACK Custom result types until CreatedAtResult/ ObjectResult implements IResult.
96
96
// See https://github.com/dotnet/aspnetcore/issues/32565.
97
97
98
- private sealed class CreatedAtResult : ObjectResult
98
+ private sealed class CreatedAtResult : IResult
99
99
{
100
100
private readonly string _location ;
101
+ private readonly object ? _value ;
101
102
102
103
internal CreatedAtResult ( string location , object ? value )
103
- : base ( value )
104
104
{
105
105
_location = location ;
106
+ _value = value ;
106
107
}
107
108
108
- public override async Task ExecuteAsync ( HttpContext httpContext )
109
- {
110
- httpContext . Response . Headers . Location = _location ;
111
- await base . ExecuteAsync ( httpContext ) ;
112
- }
113
- }
114
-
115
- private class ObjectResult : IResult
116
- {
117
- public int ? StatusCode { get ; set ; }
118
-
119
- public object ? Value { get ; set ; }
120
-
121
- internal ObjectResult ( object ? value )
122
- {
123
- Value = value ;
124
- }
125
-
126
- public virtual async Task ExecuteAsync ( HttpContext httpContext )
109
+ public async Task ExecuteAsync ( HttpContext httpContext )
127
110
{
128
111
var response = httpContext . Response ;
129
112
130
- if ( StatusCode . HasValue )
131
- {
132
- response . StatusCode = StatusCode . Value ;
133
- }
113
+ response . Headers . Location = _location ;
114
+ response . StatusCode = StatusCodes . Status201Created ;
134
115
135
- await response . WriteAsJsonAsync ( Value , httpContext . RequestAborted ) ;
116
+ await response . WriteAsJsonAsync ( _value , httpContext . RequestAborted ) ;
136
117
}
137
118
}
138
119
}
0 commit comments