GM.EntityFramework.Domain
1.2.0
See the version list below for details.
dotnet add package GM.EntityFramework.Domain --version 1.2.0
NuGet\Install-Package GM.EntityFramework.Domain -Version 1.2.0
<PackageReference Include="GM.EntityFramework.Domain" Version="1.2.0" />
<PackageVersion Include="GM.EntityFramework.Domain" Version="1.2.0" />
<PackageReference Include="GM.EntityFramework.Domain" />
paket add GM.EntityFramework.Domain --version 1.2.0
#r "nuget: GM.EntityFramework.Domain, 1.2.0"
#:package GM.EntityFramework.Domain@1.2.0
#addin nuget:?package=GM.EntityFramework.Domain&version=1.2.0
#tool nuget:?package=GM.EntityFramework.Domain&version=1.2.0
GM.EntityFramework
A lightweight DDD + Entity Framework Core toolkit for .NET: base entities, value objects, the specification pattern, a generic repository, and a unit of work with transactions and automatic auditing. Targets .NET 10.
Packages
The three packages version and release together (lockstep):
| Package | What it gives you |
|---|---|
GM.EntityFramework.Domain |
Entities, value objects, specifications, results, domain-event and repository abstractions (no EF dependency to reference in your domain layer beyond EF Core primitives). |
GM.EntityFramework.Persistence |
The EF Core implementation: GenericRepository, GenericUnitOfWork, and an auditing GenericDbContext. |
GM.EntityFramework |
Meta-package that pulls in both of the above. |
dotnet add package GM.EntityFramework
Quick start
1. Define entities
using GM.EntityFramework.Domain.Base;
public class Product : AuditableEntity<Guid> // adds CreatedAt / UpdatedAt (set automatically)
{
public string Name { get; set; } = string.Empty;
public decimal Price { get; set; }
}
Base classes: Entity<TKey> → AuditableEntity<TKey> (timestamps) →
SoftDeletableEntity<TKey> (adds IsActive / IsDeleted / IsHidden with SoftRemove(),
RestoreAll(), etc.). There's also ValueObject for equality-by-value types.
2. Create a DbContext
Inherit GenericDbContext — it stamps CreatedAt/UpdatedAt on save automatically.
using GM.EntityFramework.Persistence;
using Microsoft.EntityFrameworkCore;
public class AppDbContext(DbContextOptions options) : GenericDbContext(options)
{
public DbSet<Product> Products => Set<Product>();
}
3. Register and use the repository + unit of work
services.AddDbContext<AppDbContext>(o => o.UseSqlServer(connectionString));
services.AddScoped<IGenericUnitOfWork, GenericUnitOfWork<AppDbContext>>();
services.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<,>));
await repository.AddAsync(new Product { Name = "Book", Price = 9.99m });
await unitOfWork.SaveChangesAsync();
var cheap = await repository.FindAsync(p => p.Price < 10);
var exists = await repository.ExistsAsync(p => p.Name == "Book");
4. Specifications
Encapsulate query logic and compose it with And / Or / Not:
using GM.EntityFramework.Domain.Specifications;
public class CheapProductsSpec : BaseSpecification<Product>
{
public CheapProductsSpec()
{
AddCriteria(p => p.Price < 10);
ApplyOrdering(nameof(Product.Name));
ApplyPaging(currentPage: 1, pageSize: 20);
}
}
var page = await repository.ListAsync(new CheapProductsSpec());
5. Transactions
await unitOfWork.ExecuteInTransactionAsync(async () =>
{
await repository.AddAsync(product);
// ... more work; commits on success, rolls back on exception
});
Concurrency conflicts surface as a ConcurrencyException.
Sample application
A complete, runnable DDD + CQRS example built on these packages lives in a separate repo: GM.EntityFramework.Samples. It's a layered ASP.NET Core Web API (Domain / Application / Persistence / API) that shows how the pieces fit together in a real project:
- A
Sampleaggregate root (SoftDeletableEntity<int>,IAggregateRoot) with childSampleItementities, factory methods, and encapsulated mutations. - A custom
ISampleRepository : IGenericRepository<Sample>, implemented by deriving fromGenericRepository<Sample, ApplicationDbContext>. - An
ApplicationDbContext : GenericDbContextthat applies EF configurations from the assembly and gets automaticCreatedAt/UpdatedAtauditing for free. - A
UnitOfWork : GenericUnitOfWork<ApplicationDbContext>that exposes the aggregate repository. - CQRS commands (create / update / delete) and queries (details / list), EF Core migrations, and a PostgreSQL (Npgsql) provider.
Clone it to see the library used end-to-end.
Repository layout
GM.EntityFramework/
├── GM.EntityFramework.Domain/ # abstractions (entities, specifications, results, events)
├── GM.EntityFramework.Persistence/ # EF Core implementation (repository, UoW, DbContext)
├── GM.EntityFramework/ # meta-package
└── tests/GM.EntityFramework.Tests/ # xUnit tests (SQLite in-memory for persistence)
Building & testing
dotnet build -c Release
dotnet test -c Release
Releasing
Versioning is automated from Conventional Commits —
see CONTRIBUTING.md. All three packages share one version
(Directory.Build.props) and publish together to nuget.org on each release.
License
MIT — see LICENSE.
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.10)
- System.Linq.Dynamic.Core (>= 1.7.3)
NuGet packages (12)
Showing the top 5 NuGet packages that depend on GM.EntityFramework.Domain:
| Package | Downloads |
|---|---|
|
GM.EntityFramework.Persistence
EF Core persistence for GM.EntityFramework.Domain — a generic repository, unit of work with transactions, and an auditing DbContext. |
|
|
GM.API.Application
Application-layer building blocks for the GM.API stack: GM.Mediator wiring plus validation and performance pipeline behaviours, and paged-list models. Part of the GM.API family. |
|
|
GM.API
An opinionated ASP.NET Core Web API starter for .NET. A single AddGMAPI/UseGMAPI pair wires up controllers, CORS, API versioning, Swagger docs, FluentValidation, Serilog, and middlewares for exception handling, request logging (with sensitive-data masking) and request localization. Loads secrets into configuration from a local appsecrets.json or the store the SECRETS_PROVIDER environment variable names (Doppler, AWS Secrets Manager, Azure Key Vault, HashiCorp Vault). Bundles the GM.API.* companion packages. |
|
|
GM.FileStorage.Domain
Domain model for the GM.FileStorage catalog: the GMStoredFile aggregate (id, tenant, storage key, name, content type, size, checksum, integrity check, metadata) with soft delete and domain events for uploads, downloads, deletes and restores, and the GMStorageCleanup queue. Part of the GM.FileStorage family. |
|
|
GM.Identity.Domain
Identity domain model — users, roles, permissions, scopes, clients, sessions, and two-factor auth types — as EF Core entities for GM-based identity and access systems. |
GitHub repositories
This package is not used by any popular GitHub repositories.