Skip to content

Commit

Permalink
Update to .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
ductran95 committed Feb 7, 2024
1 parent e6d7ac6 commit 1ff6b84
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 66 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Build
run: dotnet build FastEndpoints.Extensions.All.sln --configuration Release
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Build
run: dotnet build FastEndpoints.Extensions.sln --configuration Release
Expand All @@ -31,15 +31,15 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v4

- name: Unshallow
run: git fetch --prune --unshallow

- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Create and push NuGet package
run: |
Expand Down
26 changes: 26 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" />
<GlobalPackageReference Include="MinVer" />
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="MinVer" Version="4.3.0" />
<PackageVersion Include="FastEndpoints" Version="5.22.0" />
<PackageVersion Include="FastEndpoints.Security" Version="5.22.0" />
<PackageVersion Include="OpenTelemetry" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Console" Version="1.7.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageVersion Include="FluentValidation" Version="11.9.0" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
10 changes: 4 additions & 6 deletions sample/Web/PipelineBehaviors/PostProcessors/MyResponseLogger.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using FluentValidation.Results;

namespace Web.PipelineBehaviors.PostProcessors;
namespace Web.PipelineBehaviors.PostProcessors;

public class MyResponseLogger<TRequest, TResponse> : IPostProcessor<TRequest, TResponse>
{
public Task PostProcessAsync(TRequest req, TResponse res, HttpContext ctx, IReadOnlyCollection<ValidationFailure> failures, CancellationToken ct)
public Task PostProcessAsync(IPostProcessorContext<TRequest, TResponse> context, CancellationToken ct)
{
var logger = ctx.RequestServices.GetRequiredService<ILogger<TResponse>>();
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<TResponse>>();

if (res is Sales.Orders.Create.Response response)
if (context.Response is Sales.Orders.Create.Response response)
{
logger.LogWarning($"sale complete: {response?.OrderID}");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using FluentValidation.Results;

namespace Web.PipelineBehaviors.PreProcessors;

public class AdminHeaderChecker : IGlobalPreProcessor
{
public async Task PreProcessAsync(object req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct)
public async Task PreProcessAsync(IPreProcessorContext context, CancellationToken ct)
{
if (req is Customers.Create.Request && !ctx.Request.Headers.TryGetValue("tenant-id", out _) && !ctx.Response.HasStarted)
if (context.Request is Customers.Create.Request request && !context.HttpContext.Request.Headers.TryGetValue("tenant-id", out _) && !context.HttpContext.Response.HasStarted)
{
await ctx.Response.SendForbiddenAsync(ct);
await context.HttpContext.Response.SendForbiddenAsync(ct);
}
}
}
10 changes: 4 additions & 6 deletions sample/Web/PipelineBehaviors/PreProcessors/MyRequestLogger.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using FluentValidation.Results;

namespace Web.PipelineBehaviors.PreProcessors;
namespace Web.PipelineBehaviors.PreProcessors;

public class MyRequestLogger<TRequest> : IPreProcessor<TRequest>
{
public Task PreProcessAsync(TRequest req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct)
public Task PreProcessAsync(IPreProcessorContext<TRequest> context, CancellationToken ct)
{
var logger = ctx.RequestServices.GetRequiredService<ILogger<TRequest>>();
var logger = context.HttpContext.RequestServices.GetRequiredService<ILogger<TRequest>>();

logger.LogInformation($"request:{req?.GetType().FullName} path: {ctx.Request.Path}");
logger.LogInformation($"request:{context.Request?.GetType().FullName} path: {context.HttpContext.Request.Path}");

return Task.CompletedTask;
}
Expand Down
14 changes: 6 additions & 8 deletions sample/Web/PipelineBehaviors/PreProcessors/SecurityProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using FluentValidation.Results;

namespace Web.PipelineBehaviors.PreProcessors;
namespace Web.PipelineBehaviors.PreProcessors;

public class SecurityProcessor<TRequest> : IPreProcessor<TRequest>
{
public Task PreProcessAsync(TRequest req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct)
public Task PreProcessAsync(IPreProcessorContext<TRequest> context, CancellationToken ct)
{
var tenantID = ctx.Request.Headers["tenant-id"].FirstOrDefault();
var tenantID = context.HttpContext.Request.Headers["tenant-id"].FirstOrDefault();

if (tenantID == null)
{
failures.Add(new("MissingHeaders", "The [tenant-id] header needs to be set!"));
return ctx.Response.SendErrorsAsync(failures);
context.ValidationFailures.Add(new("MissingHeaders", "The [tenant-id] header needs to be set!"));
return context.HttpContext.Response.SendErrorsAsync(context.ValidationFailures);
}

return tenantID != "qwerty" ? ctx.Response.SendForbiddenAsync() : Task.CompletedTask;
return tenantID != "qwerty" ? context.HttpContext.Response.SendForbiddenAsync() : Task.CompletedTask;
}
}
20 changes: 10 additions & 10 deletions sample/Web/Web.csproj
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591;1701;1702;CA2016;RCS1090;CA2254;CS8618</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastEndpoints.Security" Version="5.14.0" />
<PackageReference Include="FluentValidation" Version="11.6.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.20" />
<PackageReference Include="OpenTelemetry" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.5.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.5.1-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.5.1-beta.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="FastEndpoints.Security" />
<PackageReference Include="FluentValidation" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" />
<PackageReference Include="OpenTelemetry" />
<PackageReference Include="OpenTelemetry.Exporter.Console" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using FluentValidation.Results;

namespace TestCases.PreProcessorIsRunOnValidationFailure;
namespace TestCases.PreProcessorIsRunOnValidationFailure;

public class MyPreProcessor : IPreProcessor<Request>
{
public Task PreProcessAsync(Request req, HttpContext ctx, List<ValidationFailure> failures, CancellationToken ct)
public Task PreProcessAsync(IPreProcessorContext<Request> context, CancellationToken ct)
{
failures.Add(new("x", "blah"));
context.ValidationFailures.Add(new("x", "blah"));
return Task.CompletedTask;
}
}
8 changes: 1 addition & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
<PackageReference Include="MinVer" Version="4.3.0" PrivateAssets="All"/>
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" PrivateAssets="All"/>
</ItemGroup>

<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<NoWarn>$(NoWarn);1591;NU1507</NoWarn>
</PropertyGroup>

<Target Name="CustomVersion" AfterTargets="MinVer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastEndpoints" Version="5.14.0" />
<PackageReference Include="FastEndpoints" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastEndpoints" Version="5.14.0" />
<PackageReference Include="OpenTelemetry" Version="1.5.1" />
<PackageReference Include="FastEndpoints" />
<PackageReference Include="OpenTelemetry" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/FastEndpoints.Reflection/FastEndpoints.Reflection.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastEndpoints" Version="5.14.0" />
<PackageReference Include="FastEndpoints" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

<PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FastEndpoints" Version="5.14.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="FastEndpoints" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 1ff6b84

Please sign in to comment.