2m.Shared.Infrastructure
1.0.3
See the version list below for details.
dotnet add package 2m.Shared.Infrastructure --version 1.0.3
NuGet\Install-Package 2m.Shared.Infrastructure -Version 1.0.3
<PackageReference Include="2m.Shared.Infrastructure" Version="1.0.3" />
<PackageVersion Include="2m.Shared.Infrastructure" Version="1.0.3" />
<PackageReference Include="2m.Shared.Infrastructure" />
paket add 2m.Shared.Infrastructure --version 1.0.3
#r "nuget: 2m.Shared.Infrastructure, 1.0.3"
#:package 2m.Shared.Infrastructure@1.0.3
#addin nuget:?package=2m.Shared.Infrastructure&version=1.0.3
#tool nuget:?package=2m.Shared.Infrastructure&version=1.0.3
Shared Infrastructure Library
This library provides reusable components for ASP.NET Core applications, including authentication, context services, middleware, health checks, HTTP resilience, and more.
Table of Contents
- Installation
- Authentication & User Context
- Time Zone Handling
- Swagger Configuration
- MassTransit/RabbitMQ Integration
- Health Checks
- Resilient HTTP Client
- Pagination Helper
- Middleware Setup
Installation
- Add the shared infrastructure project to your solution
- Reference the project in your API application
- Register services in your application startup:
- Call
AddSharedInfrastructure()
on your service collection
- Call
- Configure the middleware pipeline:
- Use
UseSharedInfrastructure()
for standard components - Add
UseSharedHealthChecks()
for health endpoints
- Use
Authentication & User Context
Configuration
Add JWT settings to your application configuration:
- Key: 256-bit secret key for signing tokens
- Issuer: Token issuer identifier
- Audience: Valid token audience
User Context Usage
The IUserContext service provides access to:
- Current user's unique identifier
- Associated company and branch identifiers
- Role verification methods
- Claims-based information from authenticated tokens
Inject IUserContext into services to access authenticated user information throughout your application.
Time Zone Handling
Middleware Setup
Add time zone middleware to automatically handle client time zones:
- Processes "TimeZone" claim from authentication tokens
- Falls back to UTC for invalid or missing time zones
- Stores resolved time zone in request context
Service Usage
Inject ITimeZoneContext into services to:
- Convert UTC times to user's local time
- Convert local times back to UTC
- Perform time-sensitive operations in the correct time zone
Swagger Configuration
Automatically configures Swagger with JWT support when using the shared infrastructure setup.
Customization Options
- Set custom API title
- Define API version number
- Modify security scheme details
- Adjust authentication requirements
Access
- Development environment: Access at
/swagger
endpoint - Production: Secure through authentication and authorization
MassTransit/RabbitMQ Integration
Setup
Configure messaging through options:
- Specify RabbitMQ host address
- Provide connection credentials
- Register message consumers
- Configure endpoint mappings
Implementation
Create message consumers to handle specific message types. The library manages:
- Connection pooling and reconnection
- Message serialization
- Error handling
- Endpoint configuration
Health Checks
Setup
- Register health checks with
AddSharedHealthChecks()
- Enable health endpoint with
UseSharedHealthChecks()
- Configure database connection strings in application settings
Features
- PostgreSQL database connectivity check
- RabbitMQ service availability verification
- Configurable component inclusion/exclusion
- Standardized health endpoint at
/health
- Detailed status reporting
Resilient HTTP Client
Registration
Configure resilient HTTP clients with:
- Base address from configuration
- Connection pooling with automatic renewal
- Automatic retry for transient socket errors
- Configurable timeout periods
- Exponential backoff strategy for retries
Usage
Define typed clients that leverage the resilient handler. The library automatically handles:
- Transient network errors
- DNS resolution failures
- Temporary connection issues
- Socket exceptions
Pagination Helper
Usage
Apply consistent pagination to any queryable data source:
- Automatic total record count calculation
- Configurable page sizes
- Efficient data retrieval
- Standardized response structure
Response Format
- TotalCount: Total records available
- Page: Current page number
- PageSize: Number of items per page
- Data: Collection of paginated results
Middleware Setup
Standard Pipeline
Call UseSharedInfrastructure()
to enable:
- Time zone handling
- Authentication
- Authorization
- Swagger documentation UI
- Health check endpoints
Customization Options
Build custom pipelines by selectively adding components:
- TimeZoneMiddleware
- Authentication
- Authorization
- Swagger documentation
- Health checks
- Custom middleware components
Health Checks Endpoint
- Path:
/health
- Aggregates all registered health checks
- Provides machine-readable status report
- Includes detailed component health information
Support
For implementation assistance, contact: platform-engineering@yourcompany.com
Issue tracking: GitHub Issues
Documentation: Shared Infrastructure Wiki
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- AspNetCore.HealthChecks.Npgsql (>= 9.0.0)
- AspNetCore.HealthChecks.Rabbitmq (>= 9.0.0)
- AspNetCore.HealthChecks.UI.Client (>= 9.0.0)
- AutoMapper (>= 14.0.0)
- MassTransit (>= 8.4.1)
- MassTransit.RabbitMQ (>= 8.4.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.6)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.6)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Http (>= 9.0.6)
- RabbitMQ.Client (>= 7.1.2)
- Swashbuckle.AspNetCore (>= 6.5.0)
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 |
---|---|---|
1.2.1 | 154 | 6/18/2025 |
1.2.0 | 139 | 6/17/2025 |
1.1.9 | 145 | 6/17/2025 |
1.1.8 | 147 | 6/17/2025 |
1.1.6 | 147 | 6/17/2025 |
1.1.5 | 143 | 6/16/2025 |
1.1.4 | 140 | 6/16/2025 |
1.1.3 | 138 | 6/16/2025 |
1.1.2 | 163 | 6/16/2025 |
1.1.1 | 142 | 6/15/2025 |
1.1.0 | 113 | 6/15/2025 |
1.0.9 | 117 | 6/15/2025 |
1.0.8 | 110 | 6/15/2025 |
1.0.7 | 109 | 6/15/2025 |
1.0.6 | 120 | 6/15/2025 |
1.0.5 | 127 | 6/15/2025 |
1.0.4 | 137 | 6/15/2025 |
1.0.3 | 129 | 6/15/2025 |
1.0.2 | 128 | 6/15/2025 |
1.0.1 | 130 | 6/15/2025 |
1.0.0 | 133 | 6/15/2025 |