Skip to content

Commit a0b8141

Browse files
authored
Removed obsolete Microsoft.AspNetCore.Http.Abstractions (#85)
Microsoft.AspNetCore.Http.Abstractions has been marked as obsolete. dotnet/announcements#217 It appears that the only usage of the package was to provide HTTP status codes. This change replaces those usages with the System.Net.HttpStatusCode enum instead.
1 parent 019ab77 commit a0b8141

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/CommunityToolkit.Datasync.Server.EntityFrameworkCore/CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</ItemGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
1211
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
1312
</ItemGroup>
1413

src/CommunityToolkit.Datasync.Server.EntityFrameworkCore/EntityTableRepository.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using Microsoft.AspNetCore.Http;
65
using Microsoft.EntityFrameworkCore;
76
using System.Diagnostics.CodeAnalysis;
7+
using System.Net;
88

99
namespace CommunityToolkit.Datasync.Server.EntityFrameworkCore;
1010

@@ -109,7 +109,7 @@ internal async Task WrapExceptionAsync(string id, Func<Task> action, Cancellatio
109109
}
110110
catch (DbUpdateConcurrencyException ex)
111111
{
112-
throw new HttpException(StatusCodes.Status409Conflict, ex.Message, ex) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
112+
throw new HttpException((int)HttpStatusCode.Conflict, ex.Message, ex) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
113113
}
114114
catch (DbUpdateException ex)
115115
{
@@ -136,7 +136,7 @@ await WrapExceptionAsync(entity.Id, async () =>
136136
// We do not use Any() here because it is not supported by all providers (e.g. Cosmos)
137137
if (DataSet.Count(x => x.Id == entity.Id) > 0)
138138
{
139-
throw new HttpException(StatusCodes.Status409Conflict) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
139+
throw new HttpException((int)HttpStatusCode.Conflict) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
140140
}
141141

142142
UpdateManagedProperties(entity);
@@ -150,17 +150,17 @@ public virtual async ValueTask DeleteAsync(string id, byte[]? version = null, Ca
150150
{
151151
if (string.IsNullOrEmpty(id))
152152
{
153-
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
153+
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
154154
}
155155

156156
await WrapExceptionAsync(id, async () =>
157157
{
158-
TEntity storedEntity = await DataSet.FindAsync(new object[] { id }, cancellationToken).ConfigureAwait(false)
159-
?? throw new HttpException(StatusCodes.Status404NotFound);
158+
TEntity storedEntity = await DataSet.FindAsync([id], cancellationToken).ConfigureAwait(false)
159+
?? throw new HttpException((int)HttpStatusCode.NotFound);
160160

161161
if (version?.Length > 0 && !storedEntity.Version.SequenceEqual(version))
162162
{
163-
throw new HttpException(StatusCodes.Status412PreconditionFailed) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
163+
throw new HttpException((int)HttpStatusCode.PreconditionFailed) { Payload = await GetEntityAsync(id, cancellationToken).ConfigureAwait(false) };
164164
}
165165

166166
_ = DataSet.Remove(storedEntity);
@@ -173,11 +173,11 @@ public virtual async ValueTask<TEntity> ReadAsync(string id, CancellationToken c
173173
{
174174
if (string.IsNullOrEmpty(id))
175175
{
176-
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
176+
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
177177
}
178178

179179
TEntity entity = await DataSet.AsNoTracking().SingleOrDefaultAsync(x => x.Id == id, cancellationToken).ConfigureAwait(false)
180-
?? throw new HttpException(StatusCodes.Status404NotFound);
180+
?? throw new HttpException((int)HttpStatusCode.NotFound);
181181

182182
return entity;
183183
}
@@ -187,17 +187,17 @@ public virtual async ValueTask ReplaceAsync(TEntity entity, byte[]? version = nu
187187
{
188188
if (string.IsNullOrEmpty(entity.Id))
189189
{
190-
throw new HttpException(StatusCodes.Status400BadRequest, "ID is required");
190+
throw new HttpException((int)HttpStatusCode.BadRequest, "ID is required");
191191
}
192192

193193
await WrapExceptionAsync(entity.Id, async () =>
194194
{
195195
TEntity storedEntity = await DataSet.FindAsync(new object[] { entity.Id }, cancellationToken).ConfigureAwait(false)
196-
?? throw new HttpException(StatusCodes.Status404NotFound);
196+
?? throw new HttpException((int)HttpStatusCode.NotFound);
197197

198198
if (version?.Length > 0 && !storedEntity.Version.SequenceEqual(version))
199199
{
200-
throw new HttpException(StatusCodes.Status412PreconditionFailed) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
200+
throw new HttpException((int)HttpStatusCode.PreconditionFailed) { Payload = await GetEntityAsync(entity.Id, cancellationToken).ConfigureAwait(false) };
201201
}
202202

203203
UpdateManagedProperties(entity);

0 commit comments

Comments
 (0)