RGHB.Commons
1.0.1
See the version list below for details.
dotnet add package RGHB.Commons --version 1.0.1
NuGet\Install-Package RGHB.Commons -Version 1.0.1
<PackageReference Include="RGHB.Commons" Version="1.0.1" />
<PackageVersion Include="RGHB.Commons" Version="1.0.1" />
<PackageReference Include="RGHB.Commons" />
paket add RGHB.Commons --version 1.0.1
#r "nuget: RGHB.Commons, 1.0.1"
#:package RGHB.Commons@1.0.1
#addin nuget:?package=RGHB.Commons&version=1.0.1
#tool nuget:?package=RGHB.Commons&version=1.0.1
RGHB.Commons
Overview
RGHB.Commons is a .NET 9.0 library designed to provide reusable utilities and services for building data-driven applications using Entity Framework Core. It includes a generic repository pattern implementation, extension methods for query pagination, input validation utilities, and database initialization interfaces.
Features
- Generic Repository Pattern:
GenericService<TEntity>
provides a robust, type-safe implementation for CRUD operations and querying with Entity Framework Core. - Pagination Support:
EFGeneralService
offers aPage
extension method for easy query pagination. - Input Validation:
GuardExt
provides extension methods for common validation tasks like checking for null arguments, mandatory strings, consecutive characters, email addresses, and numeric strings. - Unit of Work Pattern:
IUnitOfWork
interface defines methods for managing database transactions and entity state. - Database Initialization:
IDbInitializerService
interface for initializing and seeding the database. - Flexible Querying: Supports filtering, ordering, eager loading, and projections for efficient data retrieval.
Installation
- Clone the repository or include the project as a dependency in your .NET solution.
- Ensure the following NuGet packages are installed:
Microsoft.EntityFrameworkCore
(v9.0.2)Microsoft.AspNetCore.Mvc.ViewFeatures
(v2.3.0)
- Build the project using .NET 9.0 SDK.
Usage
GenericService
The GenericService<TEntity>
class provides methods for common database operations. Example:
var service = new GenericService<MyEntity>(unitOfWork);
var entities = await service.GetPagingAsync(
pageNumZeroStart: 0,
pageSize: 10,
orderBy: q => q.OrderBy(e => e.Id),
includeProperties: "RelatedEntity"
);
Pagination
Use the Page
extension method for paginated queries:
var query = dbContext.MyEntities.AsQueryable();
var pagedResult = query.Page(pageNumZeroStart: 1, pageSize: 20);
Input Validation
Use GuardExt
for input validation:
string email = "test@example.com";
email.CheckMandatoryOption(nameof(email));
bool isValidEmail = email.IsEmailAddress(); // Returns true
Database Initialization
Implement IDbInitializerService
to initialize and seed your database:
public class MyDbInitializer : IDbInitializerService
{
public void Initialize() { /* Apply migrations */ }
public void SeedData() { /* Add default data */ }
}
Project Structure
- GeneralServices.cs: Contains the
EFGeneralService
class with pagination utilities. - GenericService.cs: Implements the generic repository pattern for Entity Framework Core.
- GuardExt.cs: Provides extension methods for input validation.
- IDbInitializerService.cs: Interface for database initialization and seeding.
- IGenericService.cs: Interface for the generic repository pattern.
- IUnitOfWork.cs: Interface for the unit of work pattern.
- RGHB.Commons.csproj: Project file specifying dependencies and target framework.
Dependencies
- .NET 9.0
- Microsoft.EntityFrameworkCore (v9.0.2)
- Microsoft.AspNetCore.Mvc.ViewFeatures (v2.3.0)
Contributing
Contributions are welcome! Please submit pull requests or open issues for bugs, feature requests, or suggestions.
License
This project is licensed under the MIT License.
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
- Microsoft.AspNetCore.Mvc.ViewFeatures (>= 2.3.0)
- Microsoft.EntityFrameworkCore (>= 9.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RGHB.Commons:
Package | Downloads |
---|---|
RGHB.DBCommons
A .NET 9.0 library providing reusable utilities for Entity Framework Core, including generic repository, pagination, and input validation. |
|
RGHB.WebCommons
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.