Skip to content

Commit 7ccf820

Browse files
authored
Merge pull request #14 from ForEvolve/remove-dependency-on-fecore
Remove dependency on ForEvolve.Core
2 parents 52ddc87 + e52aa26 commit 7ccf820

File tree

15 files changed

+41
-96
lines changed

15 files changed

+41
-96
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"image": "mcr.microsoft.com/devcontainers/dotnet"
3+
}

.github/workflows/master.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ jobs:
3838
uses: actions/setup-dotnet@v4
3939
with:
4040
dotnet-version: |
41-
6.x
42-
7.x
4341
8.x
42+
9.x
4443
4544
- name: Build
4645
run: dotnet build -c ${{ env.BUILD_CONFIGURATION }}
@@ -60,9 +59,8 @@ jobs:
6059
uses: actions/setup-dotnet@v4
6160
with:
6261
dotnet-version: |
63-
6.x
64-
7.x
6562
8.x
63+
9.x
6664
6765
- uses: dotnet/nbgv@master
6866
with:

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<RepositoryType>git</RepositoryType>
77
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
88
<LangVersion>Latest</LangVersion>
9-
<FETargetFrameworks>net6.0;net7.0;net8.0</FETargetFrameworks>
9+
<FETargetFrameworks>net8.0;net9.0</FETargetFrameworks>
1010
<FETestsTargetFrameworks>$(FETargetFrameworks)</FETestsTargetFrameworks>
1111
</PropertyGroup>
1212

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,12 @@ The prerelease CI builds are packaged and hosted at [feedz.io](feedz.io), thanks
291291

292292
# Release notes
293293

294+
## 4.0
295+
296+
- Remove support for .NET 6 and .NET 7
297+
- Add support for .NET 9
298+
- Remove dependency on ForEvolve.Core library which means the base exception is now `Exception` instead of `ForEvolve.Exception`.
299+
294300
## 3.0
295301

296302
Version 3 of ExceptionMapper is a major rewrite that simplifies the codebase and usage of the library. Here are a few important changes:

samples/WebApi.Minimal/Program.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@
99

1010
var builder = WebApplication.CreateBuilder(args);
1111
#if CHANGE_PROPERTY_NAME_POLICY
12-
#if NET8_0_OR_GREATER
1312
builder.Services.ConfigureHttpJsonOptions(options => {
1413
options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseUpper;
1514
});
16-
#else
17-
builder.Services.Configure<JsonOptions>(options => {
18-
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
19-
});
20-
#endif
2115
#endif
2216
builder.AddExceptionMapper(builder =>
2317
{
@@ -74,9 +68,7 @@
7468
"---[Others]---",
7569
"/fallback",
7670
"/a-url-that-does-not-exist",
77-
#if NET7_0_OR_GREATER
7871
"/fluent-validation?name=&description=&range=0",
79-
#endif
8072
});
8173
app.MapGet("/BadRequestException", context => throw new BadRequestException());
8274
app.MapGet("/ConflictException", context => throw new ConflictException());
@@ -96,7 +88,6 @@
9688
app.MapGet("/MyUnauthorizedException", context => throw new MyUnauthorizedException(Random.Shared.Next(100) % 2 == 0 ? "John" : "Jane"));
9789

9890
app.MapGet("/fallback", context => throw new Exception("An error that gets handled by the fallback handler."));
99-
#if NET7_0_OR_GREATER
10091
app.MapGet("/fluent-validation", ([AsParameters] Entity entity) =>
10192
{
10293
var validator = new EntityValidator();
@@ -107,7 +98,6 @@
10798
}
10899
return TypedResults.Ok(entity);
109100
});
110-
#endif
111101
app.Run();
112102

113103

src/ForEvolve.ExceptionMapper/CommonExceptions/ClientErrorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// Client error responses (400 – 499)
55
/// <br /><br />See also <seealso cref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses"/>
66
/// </summary>
7-
public abstract class ClientErrorException : ForEvolveException
7+
public abstract class ClientErrorException : Exception
88
{
99
public ClientErrorException()
1010
{

src/ForEvolve.ExceptionMapper/CommonExceptions/ServerErrorException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/// Server error responses (500 – 599)
55
/// <br /><br />See also <seealso cref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses"/>
66
/// </summary>
7-
public abstract class ServerErrorException : ForEvolveException
7+
public abstract class ServerErrorException : Exception
88
{
99
public ServerErrorException()
1010
{

src/ForEvolve.ExceptionMapper/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,16 @@ public static WebApplicationBuilder AddExceptionMapper(this WebApplicationBuilde
5353

5454
private static void AddSerializationHandler(this IServiceCollection services, IConfiguration configuration)
5555
{
56-
#if NET7_0_OR_GREATER
5756
services.ConfigureHttpJsonOptions(options => {
5857
options.SerializerOptions.DictionaryKeyPolicy = options.SerializerOptions.PropertyNamingPolicy;
5958
});
60-
#endif
6159
services
6260
.AddOptions<ProblemDetailsSerializationOptions>()
6361
.Bind(configuration.GetSection("ExceptionMapper:ProblemDetailsSerialization"))
6462
.ValidateOnStart()
6563
;
6664
services.AddSingleton(sp => sp.GetRequiredService<IOptions<ProblemDetailsSerializationOptions>>().Value);
67-
#if NET7_0_OR_GREATER
6865
services.AddProblemDetails();
69-
#endif
70-
// Workaround: binding a local copy of the DefaultProblemDetailsFactory because the .NET class is internal.
71-
// Moreover, the only way to add the class is by calling the AddMvcCore method, which add way more services.
72-
// So until we can add the DefaultProblemDetailsFactory
7366
services.TryAddSingleton<ProblemDetailsFactory, DefaultProblemDetailsFactory>();
7467
services.TryAddSingleton<IExceptionSerializer, ProblemDetailsSerializationHandler>();
7568
}

src/ForEvolve.ExceptionMapper/ForEvolve.ExceptionMapper.csproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
<ItemGroup>
99
<FrameworkReference Include="Microsoft.AspNetCore.App" />
10-
<PackageReference Include="ForEvolve.Core" Version="2.3.5" />
1110
</ItemGroup>
1211
<ItemGroup>
13-
<None Include="../../README.md" Pack="true" PackagePath="\"/>
14-
<None Include="../../LICENSE" Pack="true" PackagePath="\"/>
12+
<None Include="../../README.md" Pack="true" PackagePath="\" />
13+
<None Include="../../LICENSE" Pack="true" PackagePath="\" />
14+
</ItemGroup>
15+
<ItemGroup>
16+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="8.0.0" />
17+
<PackageReference Update="Nerdbank.GitVersioning" Version="3.7.115" />
1518
</ItemGroup>
1619
</Project>

src/ForEvolve.ExceptionMapper/Serialization/DefaultProblemDetailsFactory.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Load this only for .NET 8.
2+
#if !NET9_0_OR_GREATER
3+
// Licensed to the .NET Foundation under one or more agreements.
24
// The .NET Foundation licenses this file to you under the MIT license.
35

46
using Microsoft.AspNetCore.Http;
@@ -100,43 +102,4 @@ private void ApplyProblemDetailsDefaults(HttpContext httpContext, ProblemDetails
100102
_configure?.Invoke(new() { HttpContext = httpContext!, ProblemDetails = problemDetails });
101103
}
102104
}
103-
104-
#if NET6_0
105-
public class ProblemDetailsOptions
106-
{
107-
/// <summary>
108-
/// The operation that customizes the current <see cref="Mvc.ProblemDetails"/> instance.
109-
/// </summary>
110-
public Action<ProblemDetailsContext>? CustomizeProblemDetails { get; set; }
111-
}
112-
113-
public class ProblemDetailsContext
114-
{
115-
private ProblemDetails? _problemDetails;
116-
117-
/// <summary>
118-
/// The <see cref="HttpContext"/> associated with the current request being processed by the filter.
119-
/// </summary>
120-
public HttpContext? HttpContext { get; init; }
121-
122-
/// <summary>
123-
/// A collection of additional arbitrary metadata associated with the current request endpoint.
124-
/// </summary>
125-
public EndpointMetadataCollection? AdditionalMetadata { get; init; }
126-
127-
/// <summary>
128-
/// An instance of <see cref="ProblemDetails"/> that will be
129-
/// used during the response payload generation.
130-
/// </summary>
131-
public ProblemDetails ProblemDetails
132-
{
133-
get => _problemDetails ??= new ProblemDetails();
134-
set => _problemDetails = value;
135-
}
136-
137-
/// <summary>
138-
/// The exception causing the problem or <c>null</c> if no exception information is available.
139-
/// </summary>
140-
public Exception? Exception { get; init; }
141-
}
142-
#endif
105+
#endif

src/ForEvolve.ExceptionMapper/Serialization/Json/ProblemDetailsSerializationHandler.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ public class ProblemDetailsSerializationHandler : IExceptionSerializer
1717
private readonly ProblemDetailsFactory _problemDetailsFactory;
1818
private readonly IHostEnvironment _hostEnvironment;
1919
private readonly ProblemDetailsSerializationOptions _options;
20-
#if NET7_0_OR_GREATER
2120
private readonly IProblemDetailsService _problemDetailsService;
22-
#endif
2321
private readonly JsonSerializerOptions _jsonSerializerOptions;
2422

2523
public ProblemDetailsSerializationHandler(
26-
#if NET7_0_OR_GREATER
2724
IProblemDetailsService problemDetailsService,
28-
#endif
2925
ProblemDetailsFactory problemDetailsFactory,
3026
IHostEnvironment hostEnvironment,
3127
ProblemDetailsSerializationOptions options,
@@ -34,9 +30,7 @@ public ProblemDetailsSerializationHandler(
3430
_problemDetailsFactory = problemDetailsFactory ?? throw new ArgumentNullException(nameof(problemDetailsFactory));
3531
_hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
3632
_options = options ?? throw new ArgumentNullException(nameof(options));
37-
#if NET7_0_OR_GREATER
3833
_problemDetailsService = problemDetailsService ?? throw new ArgumentNullException(nameof(problemDetailsService));
39-
#endif
4034
_jsonSerializerOptions = jsonOptions.Value.SerializerOptions ?? throw new ArgumentNullException(nameof(jsonOptions));
4135
}
4236

@@ -113,27 +107,13 @@ public async Task ExecuteAsync(ExceptionHandlingContext ctx)
113107
}
114108

115109
// Output the problem details
116-
#if NET7_0_OR_GREATER
117110
var problemDetailsContext = new ProblemDetailsContext
118111
{
119112
HttpContext = ctx.HttpContext,
120-
#if NET8_0_OR_GREATER
121113
Exception = ctx.Error,
122-
#endif
123114
ProblemDetails = problemDetails,
124115
};
125116
await _problemDetailsService.WriteAsync(problemDetailsContext);
126-
#else
127-
#pragma warning disable CS0618 // Type or member is obsolete
128-
ctx.HttpContext.Response.ContentType = _options.ContentType;
129-
await JsonSerializer.SerializeAsync(
130-
ctx.HttpContext.Response.Body,
131-
problemDetails,
132-
_jsonSerializerOptions,
133-
cancellationToken: ctx.HttpContext.RequestAborted
134-
);
135-
#pragma warning restore CS0618 // Type or member is obsolete
136-
#endif
137117
}
138118

139119
private string FormatName(string name)

src/ForEvolve.ExceptionMapper/Serialization/Json/ProblemDetailsSerializationOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,4 @@ public class ProblemDetailsSerializationOptions
66
{
77
public bool SerializeExceptions { get; set; } = true;
88
public Func<ExceptionHandlingContext, bool> DisplayDebugInformation { get; set; } = (ExceptionHandlingContext ctx) => false;
9-
#if NET6_0
10-
private const string _obsoleteMessage = "This property was removed when targeting .NET 7+. The library now leverages the `IProblemDetailsService` interface instead.";
11-
12-
[Obsolete(_obsoleteMessage)]
13-
public string ContentType { get; set; } = "application/problem+json; charset=utf-8";
14-
#endif
159
}

test/ForEvolve.ExceptionMapper.Tests/ExceptionHandlerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ await sut.ExecuteAsync(new ExceptionHandlingContext(
6060

6161
Assert.Equal(
6262
sut.StatusCode,
63-
_httpContextHelper.HttpResponse.StatusCode
63+
_httpContextHelper.HttpResponseFake.StatusCode
6464
);
6565
}
6666

test/ForEvolve.ExceptionMapper.Tests/ForEvolve.ExceptionMapper.Tests.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@
1212
<ProjectReference Include="..\..\src\ForEvolve.ExceptionMapper\ForEvolve.ExceptionMapper.csproj" />
1313
</ItemGroup>
1414

15+
<ItemGroup>
16+
<PackageReference Update="coverlet.collector" Version="6.0.4">
17+
<PrivateAssets>all</PrivateAssets>
18+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
19+
</PackageReference>
20+
<PackageReference Update="ForEvolve.Testing.AspNetCore" Version="1.0.20" />
21+
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.14.1" />
22+
<PackageReference Update="Moq" Version="4.20.72" />
23+
<PackageReference Update="xunit" Version="2.9.3" />
24+
<PackageReference Update="xunit.runner.visualstudio" Version="3.1.1">
25+
<PrivateAssets>all</PrivateAssets>
26+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
27+
</PackageReference>
28+
</ItemGroup>
29+
1530
</Project>

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
3-
"version": "3.0",
3+
"version": "4.0",
44
"publicReleaseRefSpec": [
55
"^refs/heads/master$"
66
],

0 commit comments

Comments
 (0)