RGHB.Commons 1.0.1

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

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 a Page 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

  1. Clone the repository or include the project as a dependency in your .NET solution.
  2. Ensure the following NuGet packages are installed:
    • Microsoft.EntityFrameworkCore (v9.0.2)
    • Microsoft.AspNetCore.Mvc.ViewFeatures (v2.3.0)
  3. 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 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 (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.

Version Downloads Last Updated
1.3.0 78 9/6/2025
1.2.0 230 8/6/2025
1.1.0 158 6/25/2025
1.0.1 143 6/22/2025
1.0.0 106 6/22/2025