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

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

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature/your-feature
  5. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
1.0.2 16 8/3/2025
1.0.1 12 8/3/2025
1.0.0 101 7/27/2025