StorageGenerics 3.0.0-rc2

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

StorageGenerics

StorageGenerics is a small set of .NET libraries for building reusable CRUD data layers and ASP.NET Core APIs on top of Entity Framework Core. It provides generic repository services, queryable repositories, base API controllers, DTO mapping abstractions, and a matching HTTP client.

The library supports entities with any equatable ID type. Convenience APIs are included for the common long ID case.

License

This repository is licensed under the GNU Affero General Public License, version 3, or (at your option) any later version (AGPL-3.0-or-later).

Full license text is available in https://www.gnu.org/licenses/agpl-3.0.html.

Packages

Package Purpose
StorageGenerics.Core Entity, repository, mapper, and paging contracts shared by the other packages.
StorageGenerics Entity Framework Core repository implementations and database configuration helpers.
StorageGenerics.AspNetCore Generic read-only and CRUD API controllers, including DTO-based variants.
StorageGenerics.Client A typed HTTP client for APIs built with the ASP.NET Core package.

All projects currently target .NET 10.

Installation

Install only the packages required by your application:

dotnet add package StorageGenerics.Core
dotnet add package StorageGenerics
dotnet add package StorageGenerics.AspNetCore
dotnet add package StorageGenerics.Client

Define an entity

Entities implement IEntity<TId>. Use IEntity when the ID is a long.

using StorageGenerics.Core.Contracts;

public sealed class Product : IEntity
{
    public long Id { get; set; }
    public required string Name { get; set; }
    public decimal Price { get; set; }
}

Register a repository

Repository services use Entity Framework Core's IDbContextFactory<TContext> to create a context for individual CRUD operations. QueryableRepositoryService additionally uses a scoped context for composable queries.

using Microsoft.EntityFrameworkCore;
using StorageGenerics.Core.Contracts;
using StorageGenerics.Services;

builder.Services.AddDbContextFactory<AppDbContext>(options =>
    options.UseSqlite("Data Source=app.db"));

builder.Services.AddDbContext<AppDbContext>(options =>
    options.UseSqlite("Data Source=app.db"));

builder.Services.AddScoped<IQueryableRepositoryService<Product>,
    QueryableRepositoryService<AppDbContext, Product>>();

You can then inject the repository contract and use its CRUD or query APIs:

public sealed class ProductService(IQueryableRepositoryService<Product> repository)
{
    public ValueTask<Product?> FindAsync(long id, CancellationToken cancellationToken = default) =>
        repository.GetAsync(id, cancellationToken);

    public Task<List<Product>> FindInStockAsync(CancellationToken cancellationToken = default) =>
        repository.QueryAll()
            .Where(product => product.Price > 0)
            .OrderBy(product => product.Name)
            .ToListAsync(cancellationToken);
}

Create a CRUD API

Derive a controller from CrudBaseController<TEntity> to expose conventional endpoints under api/[controller]:

using StorageGenerics.AspNetCore.Controllers;
using StorageGenerics.Core.Contracts;

public sealed class ProductsController(
    IQueryableRepositoryService<Product> repository,
    ILogger<CrudBaseController<Product>> logger)
    : CrudBaseController<Product>(repository, logger)
{
}

The controller provides count, list, page, get-by-ID, exists, create, update, and delete endpoints. Use the ReadCrudBaseController variants for read-only APIs or the CrudDTOBaseController and ReadDTOBaseController variants when API models should be mapped through IMapper<TDto, TEntity>.

Authentication and authorization are intentionally left to the host application. Apply authorization policies to derived controllers before exposing write endpoints.

Use the HTTP client

Register CrudClient<TEntity, TId> with an HttpClient whose base address points to the API:

using StorageGenerics.Client.Clients;
using StorageGenerics.Client.Contracts;

builder.Services.AddHttpClient<ICrudClient<Product, long>, CrudClient<Product, long>>(client =>
    client.BaseAddress = new Uri("https://api.example.com"));

The default route is inferred from the entity name. Override ControllerName or Path in a derived client when the API uses a different route.

Polymorphic entity queries

For Entity Framework Core table-per-hierarchy models, OfOnlyType and ApplyOnlyTypeQueryFilter filter against the Discriminator column so a query returns only the exact requested type rather than its derived types.

Building locally

dotnet restore StorageGenerics.sln
dotnet build StorageGenerics.sln --configuration Release
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on StorageGenerics:

Package Downloads
StorageGenerics.AspNetCore

An extension of the storage generics into Asp.Net Core with a base controller for connecting with the database. All methods can be overriden.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0-rc2 90 8/13/2026
3.0.0-rc1 69 8/13/2026

Added paging extenstions.