Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add .NET 6 support #14

Merged
merged 11 commits into from
Jul 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/dotnetcore.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
framework-version: [net6.0, net5.0, netcoreapp3.1]
framework-version: [net6.0, netcoreapp3.1]

steps:
- uses: actions/checkout@master
Expand All @@ -19,11 +19,6 @@ jobs:
with:
dotnet-version: 6.0.x

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

- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
Expand Down
8 changes: 8 additions & 0 deletions Changelog.md
@@ -1,5 +1,13 @@
# Changelog

## v4.0.0-rc1

- Added .NET 6 target framework
- (breaking) Dropped .NET 5.0 support (non-LTS)
- (breaking) Removed .NET Framework 4.6 and .NET Standard below 2.0.
- (breaking) Removed `CorrelationManager` obsoleted constructors.
- (breaking) Removed obsolete `CorrelateRequests` overload accepting an `IConfiguration` parameter.

## v3.3.0

- Added .NET 5 target framework
Expand Down
10 changes: 4 additions & 6 deletions Directory.Build.props
Expand Up @@ -7,14 +7,12 @@

<PropertyGroup>
<!-- Microsoft.Extensions.* -->
<PackageVersion_Microsoft_Extensions>5.0.0</PackageVersion_Microsoft_Extensions>
<PackageVersion_Microsoft_Extensions Condition="'$(TargetFramework)'=='netstandard2.1' Or '$(TargetFramework)'=='netcoreapp3.1'">3.1.1</PackageVersion_Microsoft_Extensions>
<PackageVersion_Microsoft_Extensions Condition="'$(TargetFramework)'=='netstandard2.0' Or $(TargetFramework.StartsWith('netcoreapp2'))">2.1.0</PackageVersion_Microsoft_Extensions>
<PackageVersion_Microsoft_Extensions Condition="$(TargetFramework.StartsWith('netstandard1')) Or $(TargetFramework.StartsWith('net46')) Or $(TargetFramework.StartsWith('netcoreapp1'))">1.1.0</PackageVersion_Microsoft_Extensions>
<PackageVersion_Microsoft_Extensions>6.0.0</PackageVersion_Microsoft_Extensions>
<PackageVersion_Microsoft_Extensions Condition="'$(TargetFramework)'!='net6.0'">3.1.26</PackageVersion_Microsoft_Extensions>

<!-- System.Diagnostics.DiagnosticSource -->
<PackageVersion_DiagnosticSource>5.0.0</PackageVersion_DiagnosticSource>
<PackageVersion_DiagnosticSource Condition="'$(TargetFramework)'!='net5.0'">4.7.0</PackageVersion_DiagnosticSource>
<PackageVersion_DiagnosticSource>6.0.0</PackageVersion_DiagnosticSource>
<PackageVersion_DiagnosticSource Condition="'$(TargetFramework)'!='net6.0'">4.7.0</PackageVersion_DiagnosticSource>

</PropertyGroup>
</Project>
15 changes: 7 additions & 8 deletions README.md
Expand Up @@ -195,7 +195,7 @@ services.AddSingleton<ICorrelationIdFactory, RequestIdentifierCorrelationIdFacto

## Alternatives for more advanced Distributed Tracing

Please consider that .NET Core 3 now has built-in support for [W3C TraceContext](https://github.com/w3c/trace-context) ([blog](https://devblogs.microsoft.com/aspnet/improvements-in-net-core-3-0-for-troubleshooting-and-monitoring-distributed-apps/)) and that there are other distributed tracing libraries with more functionality than Correlate.
Please consider that .NET Core 3.1 and up now has built-in support for [W3C TraceContext](https://github.com/w3c/trace-context) ([blog](https://devblogs.microsoft.com/aspnet/improvements-in-net-core-3-0-for-troubleshooting-and-monitoring-distributed-apps/)) and that there are other distributed tracing libraries with more functionality than Correlate.

- [OpenTelemetry](https://opentelemetry.io/)
- [Jaeger](https://www.jaegertracing.io/)
Expand All @@ -204,17 +204,16 @@ Please consider that .NET Core 3 now has built-in support for [W3C TraceContext]
## More info

### Supported .NET targets
- .NET 5.0
- .NET Standard 2.1/2.0/1.3
- .NET 4.6
- .NET 6.0
- .NET Standard 2.1/.NET Core 3.1

### ASP.NET Core support
- ASP.NET Core 2.1/2.2/3.0/3.1/5.0
- ASP.NET Core 3.1/6.0

### Build requirements
- Visual Studio 2019
- .NET 5 SDK
- .NET 4.6 targetting pack
- Visual Studio 2022
- .NET 6 SDK
- .NET 3.1 SDK

#### Contributions
PR's are welcome. Please rebase before submitting, provide test coverage, and ensure the AppVeyor build passes. I will not consider PR's otherwise.
Expand Down
9 changes: 5 additions & 4 deletions src/Correlate.Abstractions/Correlate.Abstractions.csproj
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.0;netstandard1.0;net46</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<RootNamespace>Correlate</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -12,8 +11,10 @@
<PackageProjectUrl>https://github.com/skwasjer/Correlate</PackageProjectUrl>
<PackageTags>correlationid, correlation, correlate, causation, aspnet, middleware, httpclient, httpclientfactory</PackageTags>
<PackageReleaseNotes>
v3.3.0
- Added .NET 5.0 and .NET Standard 2.0 target framework
v4.0.0
- Added .NET 6.0 support
- Dropped .NET 5.0 support (non-LTS)
- Dropped support for .NET Framework 4.6 and .NET Standard 1.0
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
15 changes: 7 additions & 8 deletions src/Correlate.AspNetCore/Correlate.AspNetCore.csproj
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFrameworks>net6.0;netcoreapp3.1</TargetFrameworks>
<RootNamespace>Correlate</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -12,16 +11,16 @@
<PackageProjectUrl>https://github.com/skwasjer/Correlate</PackageProjectUrl>
<PackageTags>correlationid, correlation, correlate, causation, aspnet, middleware, httpclient, httpclientfactory</PackageTags>
<PackageReleaseNotes>
v3.3.0
- Added .NET 5.0 target framework
v4.0.0
- Added .NET 6.0 support
- Added .NET Core 3.1 support
- Dropped .NET 5.0 support (non-LTS)
- Removed .NET Core 2.1 support (implicitly by removing .NET Standard 2.0)
</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" Condition="'$(TargetFramework)'=='net5.0'" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.0" Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="System.Collections.Immutable" Version="1.7.1" Condition="'$(TargetFramework)'!='net5.0'"/>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
Expand Down
9 changes: 5 additions & 4 deletions src/Correlate.Core/Correlate.Core.csproj
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;netstandard1.3;net46</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<RootNamespace>Correlate</RootNamespace>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand All @@ -14,8 +13,10 @@
<PackageProjectUrl>https://github.com/skwasjer/Correlate</PackageProjectUrl>
<PackageTags>correlationid, correlation, correlate, causation, aspnet, middleware, httpclient, httpclientfactory</PackageTags>
<PackageReleaseNotes>
v3.3.0
- Added .NET 5 target framework
v4.0.0
- Added .NET 6.0 support
- Dropped .NET 5.0 support (non-LTS)
- Dropped support for .NET Framework 4.6 and .NET Standard 1.3
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
37 changes: 0 additions & 37 deletions src/Correlate.Core/CorrelationManager.cs
Expand Up @@ -25,43 +25,6 @@ private Void()
public static readonly Void Null = new Void();
}

/// <summary>
/// Initializes a new instance of the <see cref="CorrelationManager"/> class.
/// </summary>
/// <param name="correlationContextFactory">The correlation context factory used to create new contexts.</param>
/// <param name="correlationIdFactory">The correlation id factory used to generate a new correlation id per context.</param>
/// <param name="logger">The logger.</param>
[Obsolete("Use the Ctor() that accepts 'ICorrelationContextAccessor'.")]
public CorrelationManager
(
ICorrelationContextFactory correlationContextFactory,
ICorrelationIdFactory correlationIdFactory,
ILogger<CorrelationManager> logger
)
{
_correlationContextFactory = correlationContextFactory ?? throw new ArgumentNullException(nameof(correlationContextFactory));
_correlationIdFactory = correlationIdFactory ?? throw new ArgumentNullException(nameof(correlationIdFactory));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

/// <summary>
/// Initializes a new instance of the <see cref="CorrelationManager"/> class.
/// </summary>
/// <param name="correlationContextFactory">The correlation context factory used to create new contexts.</param>
/// <param name="correlationIdFactory">The correlation id factory used to generate a new correlation id per context.</param>
/// <param name="logger">The logger.</param>
/// <param name="diagnosticListener">The diagnostics listener to run activities on.</param>
[Obsolete("Use the Ctor() that accepts 'ICorrelationContextAccessor'.")]
public CorrelationManager(
ICorrelationContextFactory correlationContextFactory,
ICorrelationIdFactory correlationIdFactory,
ILogger<CorrelationManager> logger,
DiagnosticListener diagnosticListener
) : this(correlationContextFactory, correlationIdFactory, logger)
{
_diagnosticListener = diagnosticListener ?? throw new ArgumentNullException(nameof(diagnosticListener));
}

/// <summary>
/// Initializes a new instance of the <see cref="CorrelationManager"/> class.
/// </summary>
Expand Down
4 changes: 0 additions & 4 deletions src/Correlate.Core/GuidCorrelationIdFactory.cs
Expand Up @@ -19,11 +19,7 @@ public GuidCorrelationIdFactory()
/// <inheritdoc />
public string Create()
{
#if NETSTANDARD1_3
return Guid.NewGuid().ToString("D");
#else
return Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture);
#endif
}
}
}
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;netstandard2.1;netstandard2.0;netstandard1.3;net46</TargetFrameworks>
<IsTestProject>false</IsTestProject>
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -11,20 +10,17 @@
<PackageProjectUrl>https://github.com/skwasjer/Correlate</PackageProjectUrl>
<PackageTags>correlationid, correlation, correlate, causation, aspnet, middleware, httpclient, httpclientfactory</PackageTags>
<PackageReleaseNotes>
v3.3.0
- Added .NET 5 target framework
- Deprecated `CorrelateRequests` extension accepting `IConfiguration` instance.
v4.0.0
- Added .NET 6.0 support
- Dropped .NET 5.0 support (non-LTS)
- Dropped support for .NET Framework 4.6 and .NET Standard 1.3
</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)'=='net5.0' Or $(TargetFramework.StartsWith('netstandard2'))">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="$(PackageVersion_Microsoft_Extensions)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard1')) Or $(TargetFramework.StartsWith('net46'))">
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(PackageVersion_Microsoft_Extensions)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Correlate.Core\Correlate.Core.csproj" />
</ItemGroup>
Expand Down
@@ -1,10 +1,6 @@
#if NETSTANDARD2_0 || NETSTANDARD2_1 || NET5_0
using System;
using System;
using System.Net.Http;
using Correlate.Http;
#if NETSTANDARD2_0 || NETSTANDARD2_1
using Microsoft.Extensions.Configuration;
#endif
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
Expand All @@ -28,20 +24,6 @@ public static IHttpClientBuilder CorrelateRequests(this IHttpClientBuilder build
return builder.CorrelateRequests(options => options.RequestHeader = requestHeader);
}

#if NETSTANDARD2_0 || NETSTANDARD2_1
/// <summary>
/// Adds services required for adding correlation id to each outgoing <see cref="HttpClient"/> request.
/// </summary>
/// <param name="builder">The <see cref="IHttpClientBuilder"/> to add the services to.</param>
/// <param name="configuration">The <see cref="IConfiguration"/> used to configure <see cref="CorrelateClientOptions"/>.</param>
/// <returns>The <see cref="IHttpClientBuilder"/> so that additional calls can be chained.</returns>
[Obsolete("Will be removed in future version.")]
public static IHttpClientBuilder CorrelateRequests(this IHttpClientBuilder builder, IConfiguration configuration)
{
return builder.CorrelateRequests(configuration.Bind);
}
#endif

/// <summary>
/// Adds services required for adding correlation id to each outgoing <see cref="HttpClient"/> request.
/// </summary>
Expand Down Expand Up @@ -74,4 +56,3 @@ public static IHttpClientBuilder CorrelateRequests(this IHttpClientBuilder build
}
}
}
#endif
7 changes: 2 additions & 5 deletions src/Directory.Build.targets
Expand Up @@ -14,14 +14,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.1">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Nullable" Version="1.3.0">
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
15 changes: 0 additions & 15 deletions test/Correlate.AspNetCore.Tests/AspNetCore/Fixtures/Startup.cs
Expand Up @@ -22,20 +22,9 @@ public void ConfigureServices(IServiceCollection services)
.ConfigurePrimaryHttpMessageHandler(s => s.GetRequiredService<MockHttpHandler>())
.CorrelateRequests();

#if NETCOREAPP3_1 || NET5_0
services
.AddControllers()
.AddControllersAsServices();
#else
services
.AddMvcCore()
.AddControllersAsServices()
#if NETCOREAPP2_1
.SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1);
#else
.SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);
#endif
#endif
}

public void Configure(IApplicationBuilder app)
Expand All @@ -45,12 +34,8 @@ public void Configure(IApplicationBuilder app)

app.UseCorrelate();

#if NETCOREAPP3_1 || NET5_0
app.UseRouting();
app.UseEndpoints(builder => builder.MapControllers());
#else
app.UseMvc();
#endif
}

private class TestContextMiddleware
Expand Down
@@ -1,6 +1,7 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Core;
using Serilog.Events;
Expand Down Expand Up @@ -34,16 +35,20 @@ public bool LoggingEnabled
}
}

protected override IWebHostBuilder CreateWebHostBuilder()
protected override IHostBuilder CreateHostBuilder()
{
return WebHost.CreateDefaultBuilder()
.UseStartup<TStartup>()
return Host.CreateDefaultBuilder()
.UseEnvironment(Environments.Development)
.UseSerilog((context, configuration) =>
{
configuration
.MinimumLevel.ControlledBy(_logLevelSwitch)
.WriteTo.TestCorrelator();
}, true);
{
configuration
.MinimumLevel.ControlledBy(_logLevelSwitch)
.WriteTo.TestCorrelator();
},
true)
.ConfigureWebHost(webHostBuilder => webHostBuilder
.UseStartup<TStartup>()
);
}

protected override void ConfigureWebHost(IWebHostBuilder builder)
Expand All @@ -52,4 +57,4 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
base.ConfigureWebHost(builder);
}
}
}
}