AstreCode.Backend.Shared.Infrastructure 9.0.0.3

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

AstreCode.Backend.Shared.Infrastructure

Infrastructure layer components for AstreCode microservices.

Description

The AstreCode.Backend.Shared.Infrastructure package provides essential infrastructure layer components for building robust and scalable .NET 8.0 backend services. This package includes data access implementations, repository patterns, and external service integrations.

Installation

To install this package, use the .NET CLI:

dotnet add package AstreCode.Backend.Shared.Infrastructure

Or via Package Manager Console:

Install-Package AstreCode.Backend.Shared.Infrastructure

Features

🗄️ Data Access Layer

  • Entity Framework Core Integration: Full EF Core support
  • Multi-Database Support: SQL Server and PostgreSQL providers
  • DbContext Configuration: Optimized database context setup
  • Connection String Management: Flexible connection configuration

🏗️ Repository Pattern Implementation

  • BaseRepository: Generic repository implementation
  • CRUD Operations: Complete Create, Read, Update, Delete support
  • Query Support: Advanced querying capabilities
  • Async Operations: Full async/await support

🔄 Unit of Work Pattern

  • Transaction Management: Database transaction handling
  • Repository Coordination: Multiple repository coordination
  • Rollback Support: Automatic rollback on errors
  • Performance Optimization: Efficient database operations

🏢 Multi-Tenant Support

  • Tenant-Aware Context: Multi-tenant database support
  • Tenant Isolation: Data isolation between tenants
  • Tenant Configuration: Flexible tenant management
  • Tenant Middleware: Request-level tenant handling

🔍 Database Interceptors

  • Slow Query Interceptor: Performance monitoring
  • Query Logging: Detailed query logging
  • Performance Metrics: Database performance tracking
  • Custom Interceptors: Extensible interceptor framework

⚙️ Configuration Extensions

  • Infrastructure Configuration: Service registration helpers
  • Database Configuration: Database provider setup
  • Connection Management: Connection string configuration
  • Service Registration: Dependency injection setup

Example Usage

DbContext Setup

using Shared.Infrastructure.Context;
using Microsoft.EntityFrameworkCore;

public class ApplicationDbContext : TamkeenDbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    public DbSet<User> Users { get; set; }
    public DbSet<Order> Orders { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        
        // Configure your entities
        modelBuilder.Entity<User>(entity =>
        {
            entity.HasKey(e => e.Id);
            entity.Property(e => e.Email).IsRequired().HasMaxLength(255);
        });
    }
}

Repository Implementation

using Shared.Infrastructure.Repositories;
using Shared.Domain.Entities;

public interface IUserRepository : IBaseRepository<User>
{
    Task<User> GetByEmailAsync(string email);
    Task<List<User>> GetActiveUsersAsync();
}

public class UserRepository : BaseRepository<User>, IUserRepository
{
    public UserRepository(DbContext context) : base(context)
    {
    }

    public async Task<User> GetByEmailAsync(string email)
    {
        return await GetQueryable()
            .FirstOrDefaultAsync(u => u.Email == email);
    }

    public async Task<List<User>> GetActiveUsersAsync()
    {
        return await GetQueryable()
            .Where(u => u.IsActive)
            .ToListAsync();
    }
}

Unit of Work Pattern

using Shared.Infrastructure;

public class OrderService
{
    private readonly IUnitOfWork _unitOfWork;

    public OrderService(IUnitOfWork unitOfWork)
    {
        _unitOfWork = unitOfWork;
    }

    public async Task<Order> CreateOrderAsync(CreateOrderDto dto)
    {
        await _unitOfWork.BeginTransaction();
        try
        {
            var order = new Order
            {
                CustomerId = dto.CustomerId,
                TotalAmount = dto.TotalAmount
            };

            await _unitOfWork.GetRepository<Order>().AddAsync(order);
            await _unitOfWork.SaveChangesAsync();

            // Create order items
            foreach (var item in dto.Items)
            {
                var orderItem = new OrderItem
                {
                    OrderId = order.Id,
                    ProductId = item.ProductId,
                    Quantity = item.Quantity
                };
                await _unitOfWork.GetRepository<OrderItem>().AddAsync(orderItem);
            }

            await _unitOfWork.SaveChangesAsync();
            await _unitOfWork.CommitTransaction();

            return order;
        }
        catch
        {
            await _unitOfWork.RollbackTransaction();
            throw;
        }
    }
}

Infrastructure Configuration

using Shared.Infrastructure;

// In Program.cs
builder.Services.AddInfrastructureServices<ApplicationDbContext>(builder.Configuration);

Multi-Database Configuration

// In appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "Server=localhost;Database=MyApp;Trusted_Connection=true;TrustServerCertificate=true;",
    "PostgreSQLConnection": "Host=localhost;Database=MyApp;Username=postgres;Password=password"
  },
  "DatabaseProvider": "SqlServer" // or "PostgreSQL"
}

Tenant Configuration

// In appsettings.json
{
  "TenantSettings": {
    "DefaultTenantId": "00000000-0000-0000-0000-000000000000",
    "EnableMultiTenancy": true
  }
}

Configuration

Service Registration

// In Program.cs
builder.Services.AddInfrastructureServices<ApplicationDbContext>(builder.Configuration);

Database Provider Selection

// For SQL Server
builder.Services.AddInfrastructureServices<ApplicationDbContext>(builder.Configuration, "SqlServer");

// For PostgreSQL
builder.Services.AddInfrastructureServices<ApplicationDbContext>(builder.Configuration, "PostgreSQL");

Connection String Configuration

// In appsettings.json
{
  "ConnectionStrings": {
    "DefaultConnection": "your-connection-string-here"
  }
}

Dependencies

This package depends on the following NuGet packages:

  • Microsoft.EntityFrameworkCore (8.0.7) - Data access and ORM
  • Microsoft.EntityFrameworkCore.SqlServer (8.0.7) - SQL Server provider
  • Npgsql.EntityFrameworkCore.PostgreSQL (8.0.4) - PostgreSQL provider
  • Microsoft.EntityFrameworkCore.Design (8.0.7) - EF Core design-time tools
  • Microsoft.EntityFrameworkCore.Tools (8.0.7) - EF Core tools
  • Microsoft.Extensions.Localization (8.0.7) - Localization support

Requirements

  • .NET 8.0 or later
  • Entity Framework Core 8.0 or later
  • SQL Server 2019+ or PostgreSQL 12+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Support

For support and questions, please contact the AstreCode development team.

Changelog

See CHANGELOG.md for version history and changes.


AstreCode.Backend.Shared.Infrastructure - Version 8.0.0

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

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
9.0.0.3 597 9/22/2025
9.0.0.2 209 9/21/2025
9.0.0.1 293 9/8/2025
9.0.0 168 9/8/2025
8.0.0 169 9/8/2025