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
<PackageReference Include="AstreCode.Backend.Shared.Infrastructure" Version="9.0.0.3" />
<PackageVersion Include="AstreCode.Backend.Shared.Infrastructure" Version="9.0.0.3" />
<PackageReference Include="AstreCode.Backend.Shared.Infrastructure" />
paket add AstreCode.Backend.Shared.Infrastructure --version 9.0.0.3
#r "nuget: AstreCode.Backend.Shared.Infrastructure, 9.0.0.3"
#:package AstreCode.Backend.Shared.Infrastructure@9.0.0.3
#addin nuget:?package=AstreCode.Backend.Shared.Infrastructure&version=9.0.0.3
#tool nuget:?package=AstreCode.Backend.Shared.Infrastructure&version=9.0.0.3
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 | 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
- Aliyun.OSS.SDK.NetCore (>= 2.14.1)
- Asp.Versioning.Mvc (>= 8.1.0)
- AspNetCore.HealthChecks.NpgSql (>= 8.0.1)
- AspNetCore.HealthChecks.Rabbitmq (>= 8.0.1)
- AstreCode.Backend.Shared.API (>= 9.0.0.4)
- AutoMapper (>= 13.0.1)
- Azure.Storage.Blobs (>= 12.24.0)
- BCrypt.Net-Next (>= 4.0.3)
- File.TypeChecker (>= 4.1.1)
- Hangfire.AspNetCore (>= 1.8.20)
- Hangfire.Core (>= 1.8.20)
- Hangfire.PostgreSql (>= 1.20.12)
- JetBrains.Annotations (>= 2024.2.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.8)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Mvc.Core (>= 2.2.5)
- Microsoft.AspNetCore.StaticFiles (>= 2.2.0)
- Microsoft.AspNetCore.WebUtilities (>= 9.0.8)
- Microsoft.EntityFrameworkCore (>= 9.0.8)
- Microsoft.EntityFrameworkCore.SqlServer (>= 9.0.8)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.8)
- Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore (>= 9.0.8)
- Microsoft.Extensions.Http (>= 9.0.8)
- Microsoft.Extensions.Localization (>= 9.0.8)
- Microsoft.IdentityModel.JsonWebTokens (>= 8.0.1)
- Microsoft.IdentityModel.Tokens (>= 8.0.1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
- OCI.DotNetSDK.Common (>= 119.0.0)
- OCI.DotNetSDK.Objectstorage (>= 119.0.0)
- prometheus-net.AspNetCore (>= 8.2.1)
- RabbitMQ.Client (>= 6.8.1)
- Scrutor (>= 4.2.2)
- Seq.Extensions.Logging (>= 8.0.0)
- Serilog (>= 4.0.1)
- Serilog.AspNetCore (>= 8.0.2)
- Serilog.Enrichers.Environment (>= 3.0.1)
- Serilog.Enrichers.Thread (>= 4.0.0)
- Serilog.Extensions.Hosting (>= 8.0.0)
- Serilog.Extensions.Logging (>= 8.0.0)
- Serilog.Settings.Configuration (>= 8.0.2)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 6.0.0)
- Serilog.Sinks.Seq (>= 8.0.0)
- StackExchange.Redis (>= 2.8.16)
- Swashbuckle.AspNetCore (>= 6.7.0)
- System.Linq.Dynamic.Core (>= 1.4.6)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.