AstreCode.Backend.Shared.Integration 8.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package AstreCode.Backend.Shared.Integration --version 8.0.0
                    
NuGet\Install-Package AstreCode.Backend.Shared.Integration -Version 8.0.0
                    
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="AstreCode.Backend.Shared.Integration" Version="8.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AstreCode.Backend.Shared.Integration" Version="8.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AstreCode.Backend.Shared.Integration" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AstreCode.Backend.Shared.Integration --version 8.0.0
                    
#r "nuget: AstreCode.Backend.Shared.Integration, 8.0.0"
                    
#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.
#:package AstreCode.Backend.Shared.Integration@8.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AstreCode.Backend.Shared.Integration&version=8.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AstreCode.Backend.Shared.Integration&version=8.0.0
                    
Install as a Cake Tool

AstreCode.Backend.Shared.Integration

External service integration framework for AstreCode microservices.

Description

The AstreCode.Backend.Shared.Integration package provides essential integration components for building robust and scalable .NET 8.0 backend services. This package includes HTTP client management, external service integration, and resilience patterns for reliable service communication.

Installation

To install this package, use the .NET CLI:

dotnet add package AstreCode.Backend.Shared.Integration

Or via Package Manager Console:

Install-Package AstreCode.Backend.Shared.Integration

Features

🌐 HTTP Client Management

  • JsonHandler: JSON-based HTTP client with comprehensive error handling
  • XmlHandler: XML-based HTTP client for legacy system integration
  • Authentication Support: Multiple authentication schemes (Bearer, Basic, API Key)
  • Certificate Support: Client certificate authentication

🛡️ Resilience Patterns

  • Retry Policy: Configurable retry mechanisms with exponential backoff
  • Circuit Breaker: Automatic circuit breaking for failing services
  • Timeout Policy: Request timeout management
  • Bulkhead Isolation: Resource isolation and concurrency limiting
  • Fallback Policy: Graceful degradation with fallback responses

🔐 Authentication Integration

  • Bearer Token: JWT and OAuth token support
  • Basic Authentication: Username/password authentication
  • API Key: API key-based authentication
  • Client Certificates: X.509 certificate authentication

📊 Request/Response Handling

  • JSON Serialization: Automatic JSON serialization/deserialization
  • XML Serialization: XML request/response handling
  • Query Parameter Building: Dynamic query parameter construction
  • Header Management: Request header configuration

🔧 Configuration Extensions

  • Integration Configuration: Service registration helpers
  • Policy Configuration: Resilience policy setup
  • HttpClient Configuration: HTTP client factory setup

Example Usage

JSON Handler

using Shared.Integration.Handlers;

public class ExternalApiService
{
    private readonly IJsonHandler _jsonHandler;

    public ExternalApiService(IJsonHandler jsonHandler)
    {
        _jsonHandler = jsonHandler;
    }

    public async Task<UserDto> GetUserAsync(int userId)
    {
        var queryParams = new { id = userId };
        var headers = new Dictionary<string, string>
        {
            ["Accept"] = "application/json"
        };
        var authInfo = new AuthenticationInfo
        {
            Scheme = "Bearer",
            Token = "your-jwt-token"
        };

        return await _jsonHandler.GetDataAsync<UserDto>(
            "https://api.example.com/users",
            headers,
            queryParams,
            authInfo
        );
    }

    public async Task<UserDto> CreateUserAsync(CreateUserDto user)
    {
        var authInfo = new AuthenticationInfo
        {
            Scheme = "Bearer",
            Token = "your-jwt-token"
        };

        return await _jsonHandler.PostDataAsync<UserDto>(
            "https://api.example.com/users",
            null,
            null,
            user,
            authInfo
        );
    }
}

XML Handler

using Shared.Integration.Handlers;

public class LegacySystemService
{
    private readonly IXmlHandler _xmlHandler;

    public LegacySystemService(IXmlHandler xmlHandler)
    {
        _xmlHandler = xmlHandler;
    }

    public async Task<OrderDto> GetOrderAsync(string orderId)
    {
        var queryParams = new { orderId = orderId };
        var authInfo = new AuthenticationInfo
        {
            Scheme = "Basic",
            Username = "username",
            Password = "password"
        };

        return await _xmlHandler.GetDataAsync<OrderDto>(
            "https://legacy.example.com/orders",
            null,
            queryParams,
            authInfo
        );
    }
}

Certificate Authentication

public class SecureApiService
{
    private readonly IJsonHandler _jsonHandler;

    public async Task<SecureDataDto> GetSecureDataAsync()
    {
        var authInfo = new AuthenticationInfo
        {
            Scheme = "Certificate",
            CertificatePath = "path/to/certificate.pfx",
            CertificatePassword = "certificate-password"
        };

        return await _jsonHandler.GetDataAsync<SecureDataDto>(
            "https://secure-api.example.com/data",
            null,
            null,
            authInfo,
            includeCertificate: true,
            certficatePath: "path/to/certificate.pfx"
        );
    }
}

Integration Configuration

using Shared.Integration;

// In Program.cs
builder.Services.IntegrationConfiguration(builder.Configuration);

Custom Authentication

public class CustomAuthService
{
    private readonly IJsonHandler _jsonHandler;

    public async Task<ApiResponse> CallApiWithCustomAuthAsync()
    {
        var headers = new Dictionary<string, string>
        {
            ["X-API-Key"] = "your-api-key",
            ["X-Custom-Header"] = "custom-value"
        };

        var authInfo = new AuthenticationInfo
        {
            Scheme = "Custom"
        };

        return await _jsonHandler.GetDataAsync<ApiResponse>(
            "https://api.example.com/data",
            headers,
            null,
            authInfo
        );
    }
}

Configuration

Service Registration

// In Program.cs
builder.Services.IntegrationConfiguration(builder.Configuration);

Resilience Policy Configuration

The integration framework automatically configures the following resilience policies:

  • Retry Policy: 3 retries with exponential backoff
  • Circuit Breaker: Opens after 5 failures, stays open for 30 seconds
  • Timeout Policy: 10-second timeout per request
  • Bulkhead Policy: Maximum 5 concurrent calls with queue of 10
  • Fallback Policy: Returns ServiceUnavailable response on complete failure

Custom Policy Configuration

// You can customize policies by modifying the IntegrationConfigurationExtensions
public static void IntegrationConfiguration(this IServiceCollection services, IConfiguration configuration)
{
    services.AddHttpClient<JsonHandler>()
        .AddPolicyHandler(HttpPolicyExtensions
            .HandleTransientHttpError()
            .RetryAsync(5)) // Custom retry count
        .AddPolicyHandler(HttpPolicyExtensions
            .HandleTransientHttpError()
            .CircuitBreakerAsync(3, TimeSpan.FromSeconds(60))); // Custom circuit breaker
}

Authentication Schemes

Bearer Token

var authInfo = new AuthenticationInfo
{
    Scheme = "Bearer",
    Token = "your-jwt-token"
};

Basic Authentication

var authInfo = new AuthenticationInfo
{
    Scheme = "Basic",
    Username = "username",
    Password = "password"
};

API Key

var authInfo = new AuthenticationInfo
{
    Scheme = "ApiKey",
    ApiKey = "your-api-key"
};

Client Certificate

var authInfo = new AuthenticationInfo
{
    Scheme = "Certificate",
    CertificatePath = "path/to/certificate.pfx",
    CertificatePassword = "password"
};

Dependencies

This package depends on the following NuGet packages:

  • Microsoft.AspNetCore.WebUtilities (8.0.8) - Web utilities
  • Microsoft.Extensions.Http (8.0.0) - HTTP client factory
  • Microsoft.Extensions.Http.Polly (8.0.8) - Resilience policies

Requirements

  • .NET 8.0 or later
  • ASP.NET Core 8.0 or later

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

Support

For support and questions, please contact the AstreCode development team.

Changelog

See CHANGELOG.md for version history and changes.


AstreCode.Backend.Shared.Integration - Version 8.0.0

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
10.0.0 273 12/3/2025
9.0.0 1,871 9/8/2025
8.0.0 189 9/8/2025