Foundation.Infrastructure.Common 1.1.0

dotnet add package Foundation.Infrastructure.Common --version 1.1.0
                    
NuGet\Install-Package Foundation.Infrastructure.Common -Version 1.1.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="Foundation.Infrastructure.Common" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Foundation.Infrastructure.Common" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Foundation.Infrastructure.Common" />
                    
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 Foundation.Infrastructure.Common --version 1.1.0
                    
#r "nuget: Foundation.Infrastructure.Common, 1.1.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 Foundation.Infrastructure.Common@1.1.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=Foundation.Infrastructure.Common&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Foundation.Infrastructure.Common&version=1.1.0
                    
Install as a Cake Tool

Foundation.Infrastructure.Common

Common infrastructure implementations for Foundation microservices including caching, logging, middleware, and resilience patterns.

Features

  • Caching Decorators: Repository decorators implementing cache-aside pattern with tag-based invalidation
  • Logging: Structured logging with Serilog, including enrichers and formatters
  • Middleware: Common ASP.NET Core middleware for error handling, validation, and security
  • Resilience Policies: Polly policies for retry, circuit breaker, and timeout patterns
  • Service Extensions: DI extension methods for easy service registration

Installation

dotnet add package Foundation.Infrastructure.Common

Usage

Caching Decorators

// In your DI configuration
services.AddScoped<IProductRepository, ProductRepository>();
services.Decorate<IProductRepository, CachedProductRepository>();

// Repository implementation
public class CachedProductRepository : CachedRepositoryBase<Product>, IProductRepository
{
    public CachedProductRepository(
        IProductRepository innerRepository,
        ICacheService cacheService,
        ILogger<CachedProductRepository> logger)
        : base(innerRepository, cacheService, logger, "products")
    {
    }
}

Resilience Policies

// Configure HTTP client with resilience
services.AddHttpClient<IExternalService, ExternalService>()
    .AddPolicyHandler(ResiliencePolicies.GetRetryPolicy())
    .AddPolicyHandler(ResiliencePolicies.GetCircuitBreakerPolicy());

Middleware

// In Program.cs
app.UseMiddleware<GlobalErrorHandlingMiddleware>();
app.UseMiddleware<ValidationMiddleware>();
app.UseMiddleware<SecurityHeadersMiddleware>();

Logging Configuration

// In Program.cs
builder.Host.UseSerilog((context, services, configuration) =>
{
    configuration.ConfigureFoundationLogging(context.Configuration);
});

Components

Caching

  • CachedRepositoryBase<T>: Base class for cached repositories
  • CacheService: Distributed cache implementation with Redis
  • CacheKeyBuilder: Consistent cache key generation
  • CacheOptions: Configuration for cache behavior

Middleware

  • GlobalErrorHandlingMiddleware: Centralized error handling with structured responses
  • ValidationMiddleware: Request validation with detailed error messages
  • SecurityHeadersMiddleware: Security headers for OWASP compliance
  • RequestLoggingMiddleware: Structured request/response logging

Resilience

  • ResiliencePolicies: Pre-configured Polly policies
  • HttpClientResilienceExtensions: Extension methods for HTTP client configuration
  • ResilienceOptions: Configuration for retry and circuit breaker behavior

Logging

  • LoggingExtensions: Serilog configuration helpers
  • CorrelationIdEnricher: Add correlation IDs to all logs
  • ExceptionDetailsEnricher: Enhanced exception logging

Configuration

{
  "Caching": {
    "DefaultExpiration": "00:05:00",
    "Redis": {
      "ConnectionString": "localhost:6379",
      "InstanceName": "foundation"
    }
  },
  "Resilience": {
    "Retry": {
      "Count": 3,
      "BackoffType": "Exponential"
    },
    "CircuitBreaker": {
      "FailureThreshold": 0.5,
      "DurationOfBreak": "00:00:30"
    }
  }
}

Requirements

  • .NET 8.0 or later
  • Redis for distributed caching (optional, falls back to in-memory)
  • Foundation.Application.Contracts package

License

MIT

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 (2)

Showing the top 2 NuGet packages that depend on Foundation.Infrastructure.Common:

Package Downloads
Foundation.Client.SDK

Client SDK for Foundation microservices providing typed HTTP clients with built-in resilience, authentication, and service discovery.

Foundation.ServiceDiscovery

Service discovery infrastructure for Foundation microservices. Provides dynamic service resolution with multiple discovery providers (Kubernetes, Consul, Configuration), intelligent caching, health checking, and seamless integration with Foundation.Client.SDK.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.0 472 7/22/2025
1.0.0 472 7/22/2025