Rapid.GenericRepositoryPattern
2.0.0
See the version list below for details.
dotnet add package Rapid.GenericRepositoryPattern --version 2.0.0
NuGet\Install-Package Rapid.GenericRepositoryPattern -Version 2.0.0
<PackageReference Include="Rapid.GenericRepositoryPattern" Version="2.0.0" />
paket add Rapid.GenericRepositoryPattern --version 2.0.0
#r "nuget: Rapid.GenericRepositoryPattern, 2.0.0"
// Install Rapid.GenericRepositoryPattern as a Cake Addin #addin nuget:?package=Rapid.GenericRepositoryPattern&version=2.0.0 // Install Rapid.GenericRepositoryPattern as a Cake Tool #tool nuget:?package=Rapid.GenericRepositoryPattern&version=2.0.0
Rapid.GenericRepositoryPattern
A comprehensive Generic Repository Pattern implementation for .NET applications with advanced features including async operations, specifications pattern, Entity Framework Core integration, caching, security features, and more. Supports both .NET 8 and .NET 9.
🌟 Features
Core Features:
- ✨ Generic CRUD operations with async support
- 🔄 Unit of Work pattern implementation
- 🎯 Specification pattern for complex queries
- 📄 Pagination and sorting capabilities
- 🚀 Built-in caching mechanism
- 🗑️ Soft delete support
- 📝 Audit logging
- 💼 Transaction management
- 📦 Bulk operations with progress tracking
- 💪 Strongly typed repositories
- 🔌 Entity Framework Core integration
- 💉 Dependency Injection support
Security Features:
- 🔒 Advanced security features
- Row-level security
- Data encryption
- SQL injection prevention
- Access control
- Input validation
- Security policies
Data Management:
- 🎭 Multi-tenancy support
- 🔍 Health monitoring
- 📊 Performance optimization
- 📈 Metrics collection
- 🔄 Event sourcing
- 📝 Change tracking
- 🔁 Concurrency handling
- 🔄 Type conversions
Query Features:
- 🔍 Dynamic LINQ support
- 📊 Advanced projections
- 🔄 Custom type mappings
- 🎯 Complex filtering
- 📋 Batch operations
Validation & Error Handling:
- ✅ Comprehensive validation
- 🔄 Retry policies
- 🛡️ Error handling
- 📝 Custom validation rules
- 🔍 Input sanitization
Caching & Performance:
- 💾 Multiple cache providers
- 🚀 Cache invalidation
- 📊 Cache statistics
- 🔄 Cache tags
- 📈 Performance monitoring
Monitoring & Diagnostics:
- 📊 Health checks
- 📈 Performance metrics
- 🔍 Diagnostic events
- 📝 Audit trails
- 🔄 Operation tracking
📑 Table of Contents
- Installation
- Quick Start
- Advanced Usage
- Security Features
- Performance Optimization
- Best Practices
- API Documentation
- Migration Guide
- Contributing
- License
📥 Installation
Package Manager Console
Install-Package Rapid.GenericRepositoryPattern
.NET CLI
dotnet add package Rapid.GenericRepositoryPattern
Framework Compatibility
- .NET 8.0
- .NET 9.0
🚀 Quick Start
1. Basic Setup
Register the services in your Program.cs
or Startup.cs
:
services.AddGenericRepository<YourDbContext>(options =>
{
options.EnableCaching = true;
options.DefaultCacheDurationMinutes = 30;
options.EnableSoftDelete = true;
options.EnableAuditLogging = true;
options.EnableSecurity = true;
});
2. Define Your Entities
public class Customer : BaseEntity
{
public int Id { get; set; }
public string Name { get; set; }
[Encrypted]
public string SensitiveData { get; set; }
public string Email { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
3. Create Repository and Service
public interface ICustomerService
{
Task<Customer> CreateAsync(Customer customer);
Task<Customer?> GetByIdAsync(int id);
Task<PagedResult<Customer>> GetPagedAsync(int page, int pageSize);
}
public class CustomerService : ICustomerService
{
private readonly IRepository<Customer> _repository;
private readonly IUnitOfWork _unitOfWork;
public CustomerService(IRepository<Customer> repository, IUnitOfWork unitOfWork)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
public async Task<Customer> CreateAsync(Customer customer)
{
await _unitOfWork.BeginTransactionAsync();
try
{
var result = await _repository.AddAsync(customer);
await _unitOfWork.CommitTransactionAsync();
return result;
}
catch
{
await _unitOfWork.RollbackTransactionAsync();
throw;
}
}
public async Task<Customer?> GetByIdAsync(int id)
{
return await _repository.GetByIdAsync(id);
}
public async Task<PagedResult<Customer>> GetPagedAsync(int page, int pageSize)
{
return await _repository.GetPagedAsync(page, pageSize, "Name");
}
}
🔥 Advanced Usage
Specification Pattern
public class ActiveCustomersSpecification : BaseSpecification<Customer>
{
public ActiveCustomersSpecification()
: base(c => !c.IsDeleted)
{
AddInclude(c => c.Orders);
ApplyOrderBy(c => c.Name);
ApplyPaging(1, 10);
}
}
// Usage
var spec = new ActiveCustomersSpecification();
var customers = await _repository.GetAsync(spec);
Security Features
// Row-level security
public class CustomerSecurityPolicy : ISecurityPolicy<Customer>
{
public Expression<Func<Customer, bool>> SecurityFilter(ISecurityContext context)
{
return customer => customer.TenantId == context.GetCurrentTenantId();
}
}
// Data encryption
public class Customer
{
[Encrypted]
public string CreditCardNumber { get; set; }
}
// SQL injection prevention
public class SafeQueryProvider : ISqlSecurityProvider
{
public bool ValidateQuery(string sql)
{
// Implement validation logic
return true;
}
}
Caching
// Configure caching
services.AddGenericRepository<YourDbContext>(options =>
{
options.EnableCaching = true;
options.DefaultCacheDurationMinutes = 60;
options.CacheKeyPrefix = "YourApp";
});
// Cached queries
var customers = await _repository.GetAllCachedAsync();
var customer = await _repository.GetByIdCachedAsync(1);
Bulk Operations
// Bulk insert
await _repository.BulkInsertAsync(customers, batchSize: 1000);
// Bulk update
await _repository.BulkUpdateAsync(
c => c.Status == Status.Pending,
c => new Customer { Status = Status.Processed }
);
// Bulk delete
await _repository.BulkDeleteAsync(c => c.LastModifiedAt < DateTime.UtcNow.AddYears(-1));
📈 Performance Optimization
- Use projections for better performance:
var dtos = await _repository.ProjectToListAsync<CustomerDto>();
- Enable caching for frequently accessed data:
var cachedData = await _repository.GetAllCachedAsync(TimeSpan.FromHours(1));
- Use bulk operations for large datasets:
await _repository.BulkInsertAsync(largeDataset);
- Implement pagination:
var pagedResult = await _repository.GetPagedAsync(1, 10);
📚 Documentation
- API Documentation - Detailed API reference
- Best Practices - Guidelines and recommendations
🔄 Migration Guide
Upgrading to v2.x
- Update package reference:
<PackageReference Include="Rapid.GenericRepositoryPattern" Version="2.0.0" />
- Update configuration:
services.AddGenericRepository<YourDbContext>(options =>
{
// New options available in v2.x
options.EnableSecurity = true;
options.UseEncryption(encryptionOptions);
});
🤝 Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
💬 Support
- 📧 Email: mohaned.ghawar@rapid.com
- 🌐 Website: https://rapid.com
- 💭 Discord: Join our community
- 📚 Documentation: Full documentation
🙏 Acknowledgments
- Entity Framework Core team
- .NET community
- Our contributors
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. |
-
net8.0
- EFCore.BulkExtensions (>= 8.1.2)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.0)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.Linq.Dynamic.Core (>= 1.5.1)
-
net9.0
- EFCore.BulkExtensions (>= 8.1.2)
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 9.0.0)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Caching.Memory (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 9.0.0)
- System.Diagnostics.DiagnosticSource (>= 9.0.0)
- System.Linq.Dynamic.Core (>= 1.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.