Skip to content

Commit d725330

Browse files
authored
feat!: .NET 10 Support (#363)
* feat!: .NET 10 Support * docs: Updated README * chore: Modernized
1 parent 9145aa3 commit d725330

File tree

23 files changed

+788
-229
lines changed

23 files changed

+788
-229
lines changed

Directory.Build.props

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<_TargetFrameworks>net6.0;net7.0;net8.0;net9.0</_TargetFrameworks>
4-
<!-- Remove these properties after .NET 10 migration -->
5-
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
6-
<CheckEolTargetFramework>false</CheckEolTargetFramework>
3+
<_TargetFrameworks>net8.0;net9.0;net10.0</_TargetFrameworks>
74
</PropertyGroup>
85
<PropertyGroup>
96
<!-- Workaround, until https://github.com/GitTools/GitVersion/pull/4206 is released -->

Directory.Packages.props

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<GlobalPackageReference Include="CSharpier.MSBuild" Version="1.2.1" />
8-
<GlobalPackageReference Include="GitVersion.MsBuild" Version="6.5.0" />
98
<GlobalPackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.4" />
109
<GlobalPackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="10.0.100" />
1110
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
@@ -18,21 +17,17 @@
1817
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
1918
<PackageVersion Include="Microsoft.Testing.Extensions.CodeCoverage" Version="18.1.0" />
2019
<PackageVersion Include="NetEvolve.Extensions.TUnit" Version="3.0.0" />
21-
<PackageVersion Include="NetEvolve.SequentialGuid" Version="1.1.97" />
2220
<PackageVersion Include="NSubstitute" Version="5.3.0" />
2321
<PackageVersion Include="TUnit" Version="1.2.11" />
2422
<PackageVersion Include="Ulid" Version="1.4.1" />
2523
</ItemGroup>
24+
<ItemGroup Condition=" '$(TargetFramework)' == 'net10.0'">
25+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
26+
</ItemGroup>
2627
<ItemGroup Condition=" '$(TargetFramework)' == 'net9.0'">
2728
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.11" />
2829
</ItemGroup>
2930
<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0'">
3031
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="8.0.22" />
3132
</ItemGroup>
32-
<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0'">
33-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="7.0.20" />
34-
</ItemGroup>
35-
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0'">
36-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.36" />
37-
</ItemGroup>
3833
</Project>

README.md

Lines changed: 197 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,209 @@
11
# NetEvolve.Http.Correlation
2-
Several NuGet packages to support and use a correlation ID based on HTTP header `X-Correlation-ID` or alternatively `X-Request-ID`.
2+
3+
A comprehensive suite of NuGet packages for managing HTTP correlation IDs across distributed .NET applications. Enables request tracing and distributed logging using standard HTTP headers (`X-Correlation-ID`, or `X-Request-ID` if `X-Correlation-ID` is not present).
4+
5+
## Overview
6+
7+
This library provides a complete solution for implementing correlation IDs in your .NET applications, making it easy to track requests across microservices, logs, and distributed systems. It follows industry best practices and supports modern .NET versions (8.0, 9.0, and 10.0).
8+
9+
## Key Features
10+
11+
- **Standard HTTP Headers**: Support for `X-Correlation-ID` (primary) and `X-Request-ID` (fallback)
12+
- **ASP.NET Core Integration**: Middleware for automatic correlation ID handling
13+
- **HTTP Client Integration**: Automatic correlation ID forwarding in outgoing requests
14+
- **Flexible ID Generation**: Pluggable providers (GUID, GUID V7, ULID, or custom)
15+
- **Test-Friendly**: Dedicated test provider for predictable correlation IDs
16+
- **Modern .NET**: Full support for .NET 8.0, 9.0, and 10.0
17+
- **Source Generators**: Compile-time generation for optimal performance
318

419
## Packages
520

6-
### NetEvolve.Http.Correlation.Abstractions
21+
### Core Packages
22+
23+
#### NetEvolve.Http.Correlation.Abstractions
724
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.Abstractions)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.Abstractions)
825

9-
### NetEvolve.Http.Correlation.AspNetCore
26+
Core abstractions and interfaces for correlation ID management. Provides the foundational contracts (`IHttpCorrelationIdProvider`, `IHttpCorrelationAccessor`) and constants.
27+
28+
**[View Package Documentation →](https://github.com/dailydevops/http.correlation/blob/main/src/NetEvolve.Http.Correlation.Abstractions/README.md)**
29+
30+
#### NetEvolve.Http.Correlation.AspNetCore
1031
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.AspNetCore)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.AspNetCore)
1132

12-
### NetEvolve.Http.Correlation.HttpClient
33+
ASP.NET Core middleware and services for handling correlation IDs in web applications. Automatically reads, generates, and propagates correlation IDs.
34+
35+
**[View Package Documentation →](https://github.com/dailydevops/http.correlation/blob/main/src/NetEvolve.Http.Correlation.AspNetCore/README.md)**
36+
37+
#### NetEvolve.Http.Correlation.HttpClient
1338
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.HttpClient)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.HttpClient)
1439

15-
### NetEvolve.Http.Correlation.TestGenerator
16-
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.TestGenerator)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.TestGenerator)
40+
HTTP client delegating handler for forwarding correlation IDs in outgoing requests. Ensures correlation IDs flow through your distributed system.
41+
42+
**[View Package Documentation →](https://github.com/dailydevops/http.correlation/blob/main/src/NetEvolve.Http.Correlation.HttpClient/README.md)**
1743

18-
### NetEvolve.Http.Correlation.Ulid
44+
### Provider Packages
45+
46+
#### NetEvolve.Http.Correlation.Ulid
1947
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.Ulid)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.Ulid)
48+
49+
ULID-based correlation ID provider. Provides sortable, globally unique identifiers that are more compact than GUIDs.
50+
51+
**[View Package Documentation →](https://github.com/dailydevops/http.correlation/blob/main/src/NetEvolve.Http.Correlation.Ulid/README.md)**
52+
53+
#### NetEvolve.Http.Correlation.TestGenerator
54+
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.TestGenerator)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.TestGenerator)
55+
56+
Predictable correlation ID provider for testing scenarios. Generates sequential, deterministic IDs for reliable unit and integration tests.
57+
58+
**[View Package Documentation →](https://github.com/dailydevops/http.correlation/blob/main/src/NetEvolve.Http.Correlation.TestGenerator/README.md)**
59+
60+
## Quick Start
61+
62+
### 1. Install Packages
63+
64+
```bash
65+
# Core ASP.NET Core package
66+
dotnet add package NetEvolve.Http.Correlation.AspNetCore
67+
68+
# HTTP Client package (for outgoing requests)
69+
dotnet add package NetEvolve.Http.Correlation.HttpClient
70+
71+
# Optional: ULID provider
72+
dotnet add package NetEvolve.Http.Correlation.Ulid
73+
```
74+
75+
### 2. Configure Services
76+
77+
Add correlation services to your `Program.cs`:
78+
79+
```csharp
80+
using NetEvolve.Http.Correlation;
81+
82+
var builder = WebApplication.CreateBuilder(args);
83+
84+
// Register correlation services
85+
builder.Services.AddHttpCorrelation();
86+
87+
// Configure HTTP clients with correlation forwarding
88+
builder.Services
89+
.AddHttpClient("MyApiClient")
90+
.WithHttpCorrelation();
91+
92+
var app = builder.Build();
93+
94+
// Add middleware to the pipeline (should be early)
95+
app.UseHttpCorrelation();
96+
97+
app.MapControllers();
98+
app.Run();
99+
```
100+
101+
### 3. Access Correlation IDs
102+
103+
Inject `IHttpCorrelationAccessor` to access the current correlation ID:
104+
105+
```csharp
106+
public class OrderService
107+
{
108+
private readonly IHttpCorrelationAccessor _correlationAccessor;
109+
private readonly ILogger<OrderService> _logger;
110+
111+
public OrderService(
112+
IHttpCorrelationAccessor correlationAccessor,
113+
ILogger<OrderService> logger)
114+
{
115+
_correlationAccessor = correlationAccessor;
116+
_logger = logger;
117+
}
118+
119+
public async Task ProcessOrderAsync(Order order)
120+
{
121+
var correlationId = _correlationAccessor.CorrelationId;
122+
_logger.LogInformation(
123+
"Processing order {OrderId} with correlation ID {CorrelationId}",
124+
order.Id,
125+
correlationId);
126+
127+
// Your business logic here
128+
}
129+
}
130+
```
131+
132+
## Advanced Configuration
133+
134+
### Using ULID Provider
135+
136+
```csharp
137+
builder.Services
138+
.AddHttpCorrelation()
139+
.WithUlidGenerator();
140+
```
141+
142+
### Custom Provider
143+
144+
Implement `IHttpCorrelationIdProvider` for custom ID generation:
145+
146+
```csharp
147+
public class CustomCorrelationIdProvider : IHttpCorrelationIdProvider
148+
{
149+
public string GenerateId()
150+
{
151+
return $"CUSTOM-{DateTime.UtcNow.Ticks}";
152+
}
153+
}
154+
155+
// Register custom provider
156+
builder.Services.AddHttpCorrelation();
157+
builder.Services.AddSingleton<IHttpCorrelationIdProvider, CustomCorrelationIdProvider>();
158+
```
159+
160+
## Use Cases
161+
162+
### Distributed Logging
163+
164+
Track requests across multiple services:
165+
166+
```csharp
167+
// Service A (Entry Point)
168+
app.UseHttpCorrelation(); // Generates or reads correlation ID
169+
_logger.LogInformation("Request received"); // Logs with correlation ID
170+
171+
// Service B (Called by Service A)
172+
httpClient.GetAsync("/api/data"); // Correlation ID automatically forwarded
173+
_logger.LogInformation("Data retrieved"); // Same correlation ID in logs
174+
```
175+
176+
### Microservices Tracing
177+
178+
Follow a single user request through your entire system:
179+
180+
```
181+
User Request → API Gateway → Service A → Service B → Database
182+
[CorrelationId: abc123] flows through entire chain
183+
```
184+
185+
### Testing
186+
187+
Use predictable correlation IDs in tests:
188+
189+
```csharp
190+
builder.Services
191+
.AddHttpCorrelation()
192+
.WithTestGenerator(); // Generates predictable IDs
193+
194+
// Tests now have consistent correlation IDs
195+
```
196+
197+
## Contributing
198+
199+
Contributions are welcome! Please feel free to submit a Pull Request.
200+
201+
## License
202+
203+
Licensed under the MIT License. See [LICENSE](https://github.com/dailydevops/http.correlation/blob/main/LICENSE) for details.
204+
205+
## Repository
206+
207+
- **GitHub**: [dailydevops/http.correlation](https://github.com/dailydevops/http.correlation)
208+
- **Issues**: [Report Issues](https://github.com/dailydevops/http.correlation/issues)
209+
- **Releases**: [View Releases](https://github.com/dailydevops/http.correlation/releases)

src/NetEvolve.Http.Correlation.Abstractions/Abstractions/IHttpCorrelationAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public interface IHttpCorrelationAccessor
1515
/// <summary>
1616
/// Gets the header name, which is used.
1717
/// </summary>
18-
string? HeaderName { get; internal set; }
18+
string HeaderName { get; internal set; }
1919
}

src/NetEvolve.Http.Correlation.Abstractions/Generators/SequentialGuidCorrelationIdProvider.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/NetEvolve.Http.Correlation.Abstractions/Generators/SequentialGuidOptions.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/NetEvolve.Http.Correlation.Abstractions/NetEvolve.Http.Correlation.Abstractions.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,4 @@
1515
<ItemGroup>
1616
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1717
</ItemGroup>
18-
<ItemGroup>
19-
<PackageReference Include="NetEvolve.SequentialGuid" />
20-
</ItemGroup>
2118
</Project>
Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,78 @@
1-
Abstractions for the uniform use of Http.Correlation.
1+
# NetEvolve.Http.Correlation.Abstractions
22

3-
Based on the primary Http header `X-Correlation-ID` as well as the alternative Http header `X-Request-ID`.
3+
[![Nuget](https://img.shields.io/nuget/v/NetEvolve.Http.Correlation.Abstractions)](https://www.nuget.org/packages/NetEvolve.Http.Correlation.Abstractions)
4+
5+
Core abstractions and interfaces for HTTP correlation ID management across distributed systems.
6+
7+
## Overview
8+
9+
This package provides the foundational abstractions and interfaces for managing correlation IDs in HTTP-based applications. It defines the contracts that enable consistent correlation ID handling across different implementations and frameworks.
10+
11+
## Key Features
12+
13+
- **Core Interfaces**: Defines `IHttpCorrelationIdProvider` and `IHttpCorrelationAccessor` contracts
14+
- **Standard Constants**: Provides `CorrelationConstants` with standard header names
15+
- **Generator Support**: Includes source generators for common correlation ID providers
16+
- **Framework Agnostic**: No dependencies on specific web frameworks
17+
- **Multi-Framework Support**: Compatible with .NET 8.0, 9.0, and 10.0
18+
19+
## Installation
20+
21+
```bash
22+
dotnet add package NetEvolve.Http.Correlation.Abstractions
23+
```
24+
25+
## Core Interfaces
26+
27+
### IHttpCorrelationIdProvider
28+
29+
Interface for generating correlation IDs:
30+
31+
```csharp
32+
public interface IHttpCorrelationIdProvider
33+
{
34+
string GenerateCorrelationId();
35+
}
36+
```
37+
38+
### IHttpCorrelationAccessor
39+
40+
Interface for accessing the current correlation ID:
41+
42+
```csharp
43+
public interface IHttpCorrelationAccessor
44+
{
45+
string? CorrelationId { get; }
46+
}
47+
```
48+
49+
## Constants
50+
51+
The `CorrelationConstants` class provides standard header names:
52+
53+
- `CorrelationConstants.CorrelationIdHeaderName`: `"X-Correlation-ID"` (primary)
54+
- `CorrelationConstants.AlternativeHeaderName`: `"X-Request-ID"` (alternative)
55+
56+
## Usage
57+
58+
This package is typically not used directly but serves as a dependency for implementation packages.
59+
60+
## Related Packages
61+
62+
### Implementation Packages
63+
64+
- **[NetEvolve.Http.Correlation.AspNetCore](https://www.nuget.org/packages/NetEvolve.Http.Correlation.AspNetCore)** - ASP.NET Core middleware and services
65+
- **[NetEvolve.Http.Correlation.HttpClient](https://www.nuget.org/packages/NetEvolve.Http.Correlation.HttpClient)** - HTTP client handler for correlation forwarding
66+
67+
### Provider Packages
68+
69+
- **[NetEvolve.Http.Correlation.Ulid](https://www.nuget.org/packages/NetEvolve.Http.Correlation.Ulid)** - ULID-based correlation ID provider
70+
- **[NetEvolve.Http.Correlation.TestGenerator](https://www.nuget.org/packages/NetEvolve.Http.Correlation.TestGenerator)** - Predictable provider for testing
71+
72+
## Dependencies
73+
74+
- None (pure abstractions)
75+
76+
## License
77+
78+
Licensed under the MIT License. See [LICENSE](https://github.com/dailydevops/http.correlation/blob/main/LICENSE) for details.

src/NetEvolve.Http.Correlation.AspNetCore/HttpCorrelationAccessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public HttpCorrelationAccessor(IHttpContextAccessor httpContextAccessor) =>
1515
public string CorrelationId => _httpContextAccessor.HttpContext!.TraceIdentifier;
1616

1717
/// <inheritdoc />
18-
public string? HeaderName { get; set; }
18+
public string HeaderName { get; set; } = CorrelationConstants.HeaderName1;
1919
}

0 commit comments

Comments
 (0)