Nera.Lib.Infrastructure
1.0.2
dotnet add package Nera.Lib.Infrastructure --version 1.0.2
NuGet\Install-Package Nera.Lib.Infrastructure -Version 1.0.2
<PackageReference Include="Nera.Lib.Infrastructure" Version="1.0.2" />
<PackageVersion Include="Nera.Lib.Infrastructure" Version="1.0.2" />
<PackageReference Include="Nera.Lib.Infrastructure" />
paket add Nera.Lib.Infrastructure --version 1.0.2
#r "nuget: Nera.Lib.Infrastructure, 1.0.2"
#:package Nera.Lib.Infrastructure@1.0.2
#addin nuget:?package=Nera.Lib.Infrastructure&version=1.0.2
#tool nuget:?package=Nera.Lib.Infrastructure&version=1.0.2
Nera.Lib.Infrastructure
Infrastructure layer library providing essential building blocks for Nera applications including data persistence, caching, security, multi-tenancy, and JWT authentication.
Overview
Nera.Lib.Infrastructure
is a comprehensive infrastructure library that implements common patterns and services for enterprise applications. It provides a clean separation between business logic and infrastructure concerns, enabling scalable and maintainable .NET applications.
Features
🗃️ Data Persistence
- Entity Framework Integration: Base repositories with async support
- Repository Pattern: Generic repository with specifications
- Unit of Work: Transaction management across multiple repositories
- PostgreSQL Support: Optimized for PostgreSQL databases
- Auditable Entities: Enhanced audit trail interceptors
🔐 Security
- Password Hashing: BCrypt-based secure password hashing
- JWT Authentication: Custom JWT bearer events and token handling
- Authorization: Role-based and policy-based authorization support
🏢 Multi-Tenancy
- Domain-based Multi-tenancy: Organization context resolution
- Microservice Communication: HTTP-based service integration
- Organization Context Middleware: Automatic tenant resolution
🚀 Caching
- Multi-level Caching: In-memory and Redis caching support
- Distributed Caching: Redis integration for scalable applications
- Cache Management: Thread-safe operations with expiration support
🔧 Extensions & Utilities
- Service Collection Extensions: Dependency injection helpers
- Queryable Extensions: Enhanced LINQ operations
- Common Models: Infrastructure-specific models and enums
Installation
Install the package via NuGet Package Manager:
dotnet add package Nera.Lib.Infrastructure
Or via Package Manager Console:
Install-Package Nera.Lib.Infrastructure
Quick Start
1. Configure Services
public void ConfigureServices(IServiceCollection services)
{
// Add multi-tenancy support
services.AddDomainBasedMultiTenancy(configuration);
// Add organization context middleware
services.AddOrgContextMiddleware();
// Register password hasher
services.AddSingleton<IPasswordHasher, BCryptPasswordHasher>();
}
2. Configure Middleware
public void Configure(IApplicationBuilder app)
{
// Add organization context middleware
app.UseMiddleware<OrgContextMiddleware>();
}
3. Use Repository Pattern
public class ProductService
{
private readonly IRepository<Product, int> _productRepository;
private readonly IUnitOfWork _unitOfWork;
public ProductService(IRepository<Product, int> productRepository, IUnitOfWork unitOfWork)
{
_productRepository = productRepository;
_unitOfWork = unitOfWork;
}
public async Task<Product> CreateProductAsync(Product product)
{
await _productRepository.AddAsync(product);
await _unitOfWork.SaveChangesAsync();
return product;
}
}
4. Use Caching Service
public class DataService
{
public async Task<UserData> GetUserDataAsync(int userId)
{
var cacheKey = $"user_data_{userId}";
var cachedData = CachingService.Instance.Get<UserData>(cacheKey);
if (cachedData != null)
return cachedData;
var userData = await FetchUserDataFromDatabase(userId);
CachingService.Instance.Set(cacheKey, userData, TimeSpan.FromMinutes(30));
return userData;
}
}
Configuration
Redis Caching
Configure Redis connection in your appsettings.json
:
{
"ConnectionStrings": {
"Redis": "localhost:6379"
}
}
Multi-tenancy
Configure organization service endpoint:
{
"Services": {
"OrganizationService": {
"BaseUrl": "https://api.yourapp.com/organizations"
}
}
}
Dependencies
- .NET 9.0
- Entity Framework Core 9.0.6
- Microsoft.Extensions.Caching.StackExchangeRedis 9.0.6
- BCrypt.Net-Next 4.0.3
- Serilog 4.3.0
- Polly 8.6.2
- Nera.Lib.Core 1.0.1
Architecture
The library follows clean architecture principles:
Nera.Lib.Infrastructure/
├── Auth/ # JWT authentication components
├── Caching/ # Caching services and providers
├── Common/ # Shared enums and utilities
├── Extensions/ # Service collection extensions
├── Middleware/ # ASP.NET Core middleware
├── Models/ # Infrastructure models
├── MultiTenancy/ # Multi-tenant support
├── Persistence/ # Data access layer
│ ├── EntityFramework/ # EF Core repositories
│ └── Specifications/ # Query specifications
└── Security/ # Security implementations
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature/your-feature
- Submit a pull request
License
This project is licensed under the MIT License.
Support
For questions and support:
- Create an issue in the repository
- Contact the Nextera Systems development team
Authors
Nextera Systems - Initial work and maintenance
Part of the Nera Library ecosystem for building enterprise applications.
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
- BCrypt.Net-Next (>= 4.0.3)
- Microsoft.EntityFrameworkCore (>= 9.0.6)
- Microsoft.EntityFrameworkCore.Abstractions (>= 9.0.6)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.6)
- Microsoft.Extensions.Caching.Memory (>= 9.0.6)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.6)
- Microsoft.Extensions.Logging (>= 9.0.6)
- Microsoft.Extensions.Options (>= 9.0.6)
- Nera.Lib.Caching (>= 1.0.1)
- Nera.Lib.Core (>= 1.0.6)
- Nera.Lib.Domain (>= 1.0.5)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
- Polly (>= 8.6.2)
- Polly.Extensions.Http (>= 3.0.0)
- Serilog (>= 4.3.0)
- Serilog.Extensions.Hosting (>= 9.0.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 7.0.0)
- StackExchange.Redis (>= 2.8.41)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Nera.Lib.Infrastructure:
Package | Downloads |
---|---|
Nera.Lib.Web
Web models, business rules, aggregates, value objects, and domain services for Nera applications |
GitHub repositories
This package is not used by any popular GitHub repositories.