Vorn.EntityManagement
4.0.0-gamma
See the version list below for details.
dotnet add package Vorn.EntityManagement --version 4.0.0-gamma
NuGet\Install-Package Vorn.EntityManagement -Version 4.0.0-gamma
<PackageReference Include="Vorn.EntityManagement" Version="4.0.0-gamma" />
<PackageVersion Include="Vorn.EntityManagement" Version="4.0.0-gamma" />
<PackageReference Include="Vorn.EntityManagement" />
paket add Vorn.EntityManagement --version 4.0.0-gamma
#r "nuget: Vorn.EntityManagement, 4.0.0-gamma"
#:package Vorn.EntityManagement@4.0.0-gamma
#addin nuget:?package=Vorn.EntityManagement&version=4.0.0-gamma&prerelease
#tool nuget:?package=Vorn.EntityManagement&version=4.0.0-gamma&prerelease
Vorn.EntityManagement
Vorn.EntityManagement provides a thin domain layer for CRUD-heavy applications that rely on Entity Framework Core and MediatR. The library supplies audited entity base types, descriptor-driven queries, repository and service abstractions, cache invalidation helpers, and a Roslyn source generator that wires everything together through dependency injection so that your application code can stay focused on the domain instead of infrastructure plumbing.
Table of contents
Features
- Audited aggregate root base class – derive from
Entity
to get identifiers, created/updated/deleted timestamps and soft-delete helpers out of the box. - Descriptor based filtering – express query filters, paging and soft-delete options through
EntityDescriptor
/EntityDescriptorDto
records and theQueryExtensions.Apply
helper. - Repository abstraction – reuse the generic
EntityRepository
base to implement repositories backed by EF Core DbContexts, or implement theIEntityRepository
interface for other stores. - Mediator powered CRUD – ready-made MediatR commands, queries and handlers cover add, update, delete, list, count and paged scenarios so you can orchestrate persistence with a single
IMediator
dependency. - Service façade –
EntityService
wraps the mediator pipeline with DTO mapping helpers, descriptor conversions and convenience APIs for single item, bulk and paged operations. - Cache support – memory cache helpers and invalidators keep entities warm in
IMemoryCache
while automatically evicting stale data during EF Core SaveChanges intercepts. - Auditing & notifications – the
EntityManagementInterceptor
updates audit fields, performs soft delete handling, invalidates caches and publishesEntityNotification
messages after each successful save. - Source generator registration – annotate your assembly and descriptors and the Roslyn generator will emit an
EntityManagementRegistration
helper that registers handlers, caches and interceptors in the DI container automatically.
Installation
Install the library from NuGet:
dotnet add package Vorn.EntityManagement --version 2.2.1
The package ships with the generator analyzer so you only need a single dependency.
Getting started
1. Declare entities and descriptors
Derive your domain entity from Entity
and create a descriptor that inherits from EntityDescriptor
. Apply the generator attributes so the source generator can discover the relationship between the two types:
using Vorn.EntityManagement;
using Vorn.EntityManagement.Generators;
[assembly: GenerateEntityManagementRegistration]
[EntityDescriptorFor(typeof(Customer))]
public sealed record CustomerDescriptor : EntityDescriptor;
public sealed class Customer : Entity
{
public Customer() => Id = Guid.NewGuid();
public string Name { get; set; } = string.Empty;
}
The example mirrors the test entity used in this repository – the entity automatically inherits audit fields while the descriptor advertises the filterable properties and ties into the generator.
2. Implement a repository
For EF Core scenarios subclass EntityRepository<TEntity, TDescriptor, TDbContext>
and override behavior as needed. Alternatively, implement IEntityRepository
manually for non-EF persistence; the in-memory test double illustrates the required methods.
3. Register MediatR handlers
Once the generator runs it emits a static EntityManagementRegistration.AddGeneratedEntityHandlers
helper. Call it when building your service provider, add MediatR, and register your repository implementation:
ServiceCollection services = new();
services.AddSingleton<ServiceFactory>(p => p.GetService!);
services.AddTransient<IMediator, Mediator>();
EntityManagementRegistration.AddGeneratedEntityHandlers(services);
services.AddSingleton<IEntityRepository<Customer, CustomerDescriptor>, CustomerRepository>();
This matches the pattern exercised in the integration tests and ensures every command, query, cache and interceptor dependency is wired automatically.
4. Issue CRUD requests
With DI configured you can route persistence through IMediator
. Use the generated commands and queries to add, update, fetch, list or remove entities:
Customer customer = new() { Name = "Initial" };
Customer? added = await mediator.Send(new AddEntityCommand<Customer, CustomerDescriptor>(customer));
Customer? fetched = await mediator.Send(new GetEntityByIdQuery<Customer, CustomerDescriptor>(customer.Id));
customer.Name = "Updated";
await mediator.Send(new UpdateEntityCommand<Customer, CustomerDescriptor>(customer));
await mediator.Send(new RemoveEntityCommand<Customer, CustomerDescriptor>(customer));
int count = await mediator.Send(new CountEntitiesQuery<Customer, CustomerDescriptor>(new CustomerDescriptor()));
The integration tests demonstrate the same end-to-end flow against the in-memory repository.
5. Add higher level services (optional)
EntityService
wraps the mediator with mapping delegates so that application layers can work with DTOs instead of entities, handle bulk operations, convert descriptor DTOs and retrieve paged results from a single abstraction.
6. Plug into Entity Framework Core
Register the EntityManagementInterceptor
as a SaveChangesInterceptor
for your DbContext. The interceptor stamps audit fields, converts hard deletes into soft deletes, triggers cache invalidation and publishes notifications after the save succeeds. It also clears pending notifications when a transaction fails.
7. Cache entities
Use the provided EntityMemoryCache<TEntity>
to warm frequently accessed aggregates and pair it with EntityCacheInvalidator<TEntity>
(or your own IEntityCacheInvalidator
implementation) to keep cache entries synchronized with persistence operations.
8. React to domain notifications
Every intercepted save emits EntityNotification<TId>
instances describing the affected entity, operation type and captured field deltas. Subscribe to them with MediatR notification handlers to orchestrate downstream workflows or integration events.
Descriptor-driven querying
Descriptors double as request models for complex filters. Populate properties like CreatedFrom
, UpdatedBy
, IsDeleted
, Skip
and Take
, then pass them into any GetEntitiesQuery
or repository call. The shared QueryExtensions.Apply
routine applies the filters, paging and soft-delete rules to the EF Core queryable, automatically toggling IgnoreQueryFilters
when deleted records are requested.
NuGet package layout
The package exposes the runtime library, links the generator attributes into the main assembly, and includes the analyzer output so consumers receive handler registrations without extra references.
Development
- Run the automated test suite with
dotnet test
to validate repository, cache and interceptor behavior. - Create a NuGet package locally via
dotnet pack -c Release
, which respects the project metadata and bundles the analyzer bits alongside the library.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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. |
-
net8.0
- MediatR (>= 11.1.0)
- Microsoft.EntityFrameworkCore (>= 8.0.19)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Vorn.EntityManagement:
Package | Downloads |
---|---|
Vorn.EntityManagement.SignalR.Server
This library provides SignalR entity server base class. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
4.6.0-beta | 17 | 10/5/2025 |
4.6.0-alpha | 20 | 10/5/2025 |
4.5.0 | 42 | 10/4/2025 |
4.4.0 | 230 | 9/24/2025 |
4.3.0 | 234 | 9/23/2025 |
4.0.0 | 245 | 9/22/2025 |
4.0.0-rc3 | 162 | 9/21/2025 |
4.0.0-rc2 | 141 | 9/21/2025 |
4.0.0-rc1 | 149 | 9/21/2025 |
4.0.0-gamma | 164 | 9/20/2025 |
4.0.0-delta | 160 | 9/20/2025 |
4.0.0-beta | 158 | 9/20/2025 |
4.0.0-alpha | 178 | 9/20/2025 |
3.5.0 | 328 | 9/17/2025 |
3.4.0 | 305 | 9/17/2025 |
3.3.0 | 310 | 9/17/2025 |
3.0.0 | 344 | 9/16/2025 |
2.3.0 | 178 | 9/8/2025 |
2.2.1 | 119 | 9/6/2025 |
2.2.0 | 88 | 9/6/2025 |
2.1.1 | 81 | 9/6/2025 |
2.1.0 | 93 | 9/6/2025 |
2.0.0 | 234 | 9/1/2025 |
1.0.0 | 223 | 8/27/2025 |