MGenericRepository 2.0.1

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

NuGet Downloads NuGet Version NuGet Pre-release Version License

Generic Repository for .NET Core

The Generic Repository pattern is used to simplify data access operations in .NET Core applications. This package offers support for CRUD operations, custom queries, and Unit of Work for transaction management. It helps keep your code clean, understandable, and maintainable.

Features:

  • CRUD Operations: Provides basic Create, Read, Update, and Delete operations for entities.
  • Custom Queries: Allows you to create custom queries using LINQ and Expression trees.
  • Asynchronous Support: All operations are supported asynchronously using async/await.
  • Unit of Work Support: Integrates Unit of Work for transaction management and consistency.

Installation

To install the package, use the following command:

dotnet add package MGenericRepository 
Create Repository
public interface IProductRepository : IRepository<Product>
{
}

 public class ProductRepository : Repository<Product, ApplicationDbContext>, IProductRepository
 {
     public ProductRepository(ApplicationDbContext context) : base(context)
     {
     }
 }


Usage Examples

 public interface IProductService
 {
     Task<List<Product>> GetProducts(int page, int pageSize);
     Task<Product> GetProduct(int id);
     Task<Product> AddProduct(Product product);
     Task<Product> UpdateProduct(Product product);
 }

  public class ProductService : IProductService
  {
      private readonly IProductRepository repository;
      private readonly IUnitOfWork unitOfWork;


      public ProductService(IProductRepository repository, IUnitOfWork unitOfWork)
      {
          this.repository = repository;
          this.unitOfWork = unitOfWork;
      }

      public async Task<List<Product>> GetProducts()
      {
          return await repository.GetAllAsync();
      }
      public async Task<Product> AddProduct(Product product)
      {
          await repository.AddAsync(product);
          await unitOfWork.SaveChangesAsync();
          return product;
      }
}

Implementation in program.cs
  • 1-) If you are using the repository in a single layer
   builder.Services.AddGenericRepository(options =>
    {
        options.UseDbContext<ApplicationDbContext>();
        // options.RegisterServicesFromAssembly(typeof(ProductRepository).Assembly); // Register services from the specified assembly)
        // Assembly will be auto-registered: uses the calling assembly by default
    });

  • 2-) If you are using Clean Architecture / Onion Architecture
    builder.Services.AddGenericRepository(options =>
    {
        options.UseDbContext<ApplicationDbContext>();

        var persistenceAssembly = typeof(ProductRepository).Assembly;
        var applicationAssembly = typeof(IProductRepository).Assembly;

        options.RegisterServicesFromAssemblies(persistenceAssembly, applicationAssembly);
    });

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
2.0.1 158 8/30/2025
2.0.0 153 6/29/2025
1.0.3 111 3/29/2025
1.0.2 102 3/29/2025

Repository Nugget Package