DMNSN.AspNetCore.Middlewares.CorrelationId 8.0.3

dotnet add package DMNSN.AspNetCore.Middlewares.CorrelationId --version 8.0.3                
NuGet\Install-Package DMNSN.AspNetCore.Middlewares.CorrelationId -Version 8.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DMNSN.AspNetCore.Middlewares.CorrelationId" Version="8.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DMNSN.AspNetCore.Middlewares.CorrelationId --version 8.0.3                
#r "nuget: DMNSN.AspNetCore.Middlewares.CorrelationId, 8.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DMNSN.AspNetCore.Middlewares.CorrelationId as a Cake Addin
#addin nuget:?package=DMNSN.AspNetCore.Middlewares.CorrelationId&version=8.0.3

// Install DMNSN.AspNetCore.Middlewares.CorrelationId as a Cake Tool
#tool nuget:?package=DMNSN.AspNetCore.Middlewares.CorrelationId&version=8.0.3                

Correlation ID Middleware for ASP.NET Core

This middleware is designed to monitor and manage correlation IDs across incoming requests and outgoing responses in ASP.NET Core applications. It ensures that every operation within your application can be traced with a unique identifier, making debugging and monitoring significantly easier.

Features

  • Automatic Correlation ID Management: Automatically assigns a correlation ID to incoming requests if one is not present.
  • Customizable Correlation ID Key: Allows customization of the HTTP header key used for the correlation ID.
  • Configurable through appsettings.json: Easily configure the middleware's behavior through the application's configuration file.

Solution Structure

The solution is structured into two main projects:

  • DMNSN.AspNetCore.Middlewares.CorrelationId: The core middleware project.
  • DMNSN.AspNetCore.Middlewares.CorrelationId.xUnit: The test project for the middleware.

DMNSN.AspNetCore.Middlewares.CorrelationId

This project contains the implementation of the Correlation ID middleware. It is responsible for adding a unique correlation ID to the HTTP context of each incoming request. This can then be used for logging and tracing purposes.

DMNSN.AspNetCore.Middlewares.CorrelationId.xUnit

This project contains the unit tests for the Correlation ID middleware, ensuring its functionality works as expected. It uses xUnit for testing and includes tests for both enabling and disabling the middleware.

Getting Started

To get started with using the Correlation ID middleware in your project, please see detail in this section.

Prerequisites

  • .NET 8.0 SDK or later
  • An existing ASP.NET Core project

Installation

  1. Add the middleware to your project by including it in your csproj file or using NuGet Package Manager.

  2. Ensure your project file (DMNSN.AspNetCore.Middlewares.CorrelationId.csproj) includes the necessary dependencies:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
</ItemGroup>

Usage

  1. In your Startup.cs or wherever you configure your HTTP request pipeline, add the middleware:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    // Other configurations...

    app.UseCorrelationIdMiddleware(Configuration);

    // Continue with the rest of the pipeline...
}
  1. Optionally, you can customize the middleware options by adding a section in your appsettings.json:
"DMNSN": {
    "Middlewares": {
        "CorrelationId": {
            "EnableFeature": true,
            "CorrelationKey": "X-Correlation-ID"
        }
    }
}
  1. If you prefer to pass options programmatically, you can use the UseCorrelationIdMiddleware extension method:
app.UseCorrelationIdMiddleware(new CorrelationIdMiddlewareOptions
{
    EnableFeature = true,
    CorrelationKey = "X-Correlation-ID"
});

Running the Tests

To run the tests for the Correlation ID middleware, navigate to the DMNSN.AspNetCore.Middlewares.CorrelationId.xUnit project directory and execute the following command:

This will run all the unit tests in the project and output the results.

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues to discuss potential improvements or fixes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.3 84 7/23/2024
8.0.2 81 7/22/2024
0.0.1 80 7/22/2024

Initial release. Starting base version with version of dotnet