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
<PackageReference Include="Foundation.Infrastructure.Common" Version="1.1.0" />
<PackageVersion Include="Foundation.Infrastructure.Common" Version="1.1.0" />
<PackageReference Include="Foundation.Infrastructure.Common" />
paket add Foundation.Infrastructure.Common --version 1.1.0
#r "nuget: Foundation.Infrastructure.Common, 1.1.0"
#:package Foundation.Infrastructure.Common@1.1.0
#addin nuget:?package=Foundation.Infrastructure.Common&version=1.1.0
#tool nuget:?package=Foundation.Infrastructure.Common&version=1.1.0
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 repositoriesCacheService
: Distributed cache implementation with RedisCacheKeyBuilder
: Consistent cache key generationCacheOptions
: Configuration for cache behavior
Middleware
GlobalErrorHandlingMiddleware
: Centralized error handling with structured responsesValidationMiddleware
: Request validation with detailed error messagesSecurityHeadersMiddleware
: Security headers for OWASP complianceRequestLoggingMiddleware
: Structured request/response logging
Resilience
ResiliencePolicies
: Pre-configured Polly policiesHttpClientResilienceExtensions
: Extension methods for HTTP client configurationResilienceOptions
: Configuration for retry and circuit breaker behavior
Logging
LoggingExtensions
: Serilog configuration helpersCorrelationIdEnricher
: Add correlation IDs to all logsExceptionDetailsEnricher
: 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 | Versions 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. |
-
net8.0
- Foundation.Application.Contracts (>= 1.1.0)
- Foundation.Domain.Models (>= 1.1.0)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 8.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Http.Polly (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Polly (>= 8.2.0)
- Serilog (>= 3.1.1)
- Serilog.Enrichers.Environment (>= 2.3.0)
- Serilog.Enrichers.Span (>= 3.1.0)
- Serilog.Enrichers.Thread (>= 3.1.0)
- Serilog.Extensions.Hosting (>= 8.0.0)
- Serilog.Extensions.Logging (>= 8.0.0)
- Serilog.Sinks.Console (>= 5.0.1)
- Serilog.Sinks.Debug (>= 2.0.0)
- Serilog.Sinks.File (>= 5.0.0)
- Serilog.Sinks.Seq (>= 6.0.0)
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.