DKNet.EfCore.Events
10.1.19
dotnet add package DKNet.EfCore.Events --version 10.1.19
NuGet\Install-Package DKNet.EfCore.Events -Version 10.1.19
<PackageReference Include="DKNet.EfCore.Events" Version="10.1.19" />
<PackageVersion Include="DKNet.EfCore.Events" Version="10.1.19" />
<PackageReference Include="DKNet.EfCore.Events" />
paket add DKNet.EfCore.Events --version 10.1.19
#r "nuget: DKNet.EfCore.Events, 10.1.19"
#:package DKNet.EfCore.Events@10.1.19
#addin nuget:?package=DKNet.EfCore.Events&version=10.1.19
#tool nuget:?package=DKNet.EfCore.Events&version=10.1.19
DKNet.EfCore.Events
Dispatches domain events raised by entities during EF Core SaveChanges. An entity queues a plain object from a
business method (AddEvent(...)); this package publishes it after the save has actually committed — never
before, never for a save that fails.
Features
AddEvent(object)/AddEvent<TEvent>()on anyIEventEntity(already implemented byEntity<TKey>/EntityinDKNet.EfCore.Abstractions) to queue events from domain methods.- Automatic dispatch after a successful
SaveChanges, via anEventHookthat plugs into the same save pipeline asDKNet.EfCore.Hooks. [RaisesEvent]declared events — raise events by attribute instead of by hand, with noIEventEntityrequirement (needsDKNet.EfCore.DtoGeneratorfor the payload).IEventPublisher/DefaultEventPublisherabstraction — plug in any messaging technology; multiple publishers can be registered and all run per save.EventExceptionsurfaces missingIMapperregistrations and unresolved declared-event payloads instead of failing silently.
Install
dotnet add package DKNet.EfCore.Events
Quick start
public record OrderPlacedEvent(Guid OrderId, decimal Total);
public class Order : Entity<Guid>
{
public Order(Guid id, decimal total) : base(id)
{
Total = total;
AddEvent(new OrderPlacedEvent(id, total)); // queued, not dispatched yet
}
public decimal Total { get; private set; }
}
public sealed class LoggingEventPublisher(ILogger<LoggingEventPublisher> logger) : DefaultEventPublisher
{
public override Task PublishAsync(object eventObj, CancellationToken cancellationToken = default)
{
logger.LogInformation("Publishing {EventType}", eventObj.GetType().Name);
return Task.CompletedTask;
}
}
// Startup — DbContext must be hook-aware for events to dispatch at all
services.AddDbContextWithHook<AppDbContext>((_, o) => o.UseSqlServer(connectionString));
services.AddEventPublisher<AppDbContext, LoggingEventPublisher>();
// Usage
db.Orders.Add(new Order(Guid.NewGuid(), 42.00m));
await db.SaveChangesAsync(); // OrderPlacedEvent reaches LoggingEventPublisher only after this commits
Customisation reference
There is no options class — every knob is a DI registration.
| Knob | Lifetime | Required? | Effect |
|---|---|---|---|
AddEventPublisher<TDbContext, TPublisher>() |
publisher is scoped | yes | Registers TPublisher as an IEventPublisher and EventHook as a hook for TDbContext. Repeating it with the same implementation is a no-op; different implementations all register, and every one runs on every save. |
AddDbContextWithHook<TDbContext>() or options.UseHooks<TDbContext>(provider) |
— | yes | Installs the interceptor. Without it EventHook sits in DI and is never invoked. |
MapsterMapper.IMapper |
your choice | only for AddEvent<TEvent>() and [RaisesEvent] |
Maps the entity onto the payload type. EventHook uses the first registered IMapper. Missing it throws EventException at dispatch time. |
ILogger<EventHook> |
your choice | no | One informational entry per AfterSaveAsync, one error entry per failed publisher. |
Behaviour that is deliberately not configurable: dispatch happens only after a successful save, a publisher that throws is logged and swallowed so the other publishers still run, and there is no retry, ordering knob, or dead-letter path.
Full documentation
Registration details, the complete dispatch lifecycle, [RaisesEvent] declared events, configuration, and how
this composes with DKNet.EfCore.Abstractions and DKNet.EfCore.Hooks:
https://github.com/baoduy/DKNet/blob/main/docs/EfCore/DKNet.EfCore.Events.md
| 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
- DKNet.EfCore.Abstractions (>= 10.1.19)
- DKNet.EfCore.Hooks (>= 10.1.19)
- FluentResults (>= 4.0.0)
- Mapster (>= 10.0.12)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DKNet.EfCore.Events:
| Package | Downloads |
|---|---|
|
DKNet.SlimBus.Extensions
DKNet is an enterprise-grade .NET library collection focused on advanced EF Core extensions, dynamic predicate building, and the Specification pattern. It provides production-ready tools for building robust, type-safe, and testable data access layers, including dynamic LINQ support, LinqKit integration. Designed for modern cloud-native applications, DKNet enforces strict code quality, async best practices, and full documentation for all public APIs. Enterprise-grade .NET library suite for modern application development, featuring advanced EF Core extensions (dynamic predicates, specifications, LinqKit), robust Domain-Driven Design (DDD) patterns, and domain event support. DKNet empowers scalable, maintainable, and testable solutions with type-safe validation, async/await, XML documentation, and high code quality standards. Ideal for cloud-native, microservices, and enterprise architectures. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.19 | 33 | 9/3/2026 |
| 10.1.18 | 31 | 9/3/2026 |
| 10.1.17 | 37 | 9/3/2026 |
| 10.1.16 | 36 | 9/3/2026 |
| 10.1.15 | 101 | 9/1/2026 |
| 10.1.14 | 80 | 9/1/2026 |
| 10.1.13 | 96 | 8/31/2026 |
| 10.1.12 | 119 | 8/25/2026 |
| 10.1.11 | 118 | 8/24/2026 |
| 10.1.10 | 127 | 8/22/2026 |
| 10.1.9 | 128 | 8/22/2026 |
| 10.1.8 | 109 | 8/21/2026 |
| 10.1.7 | 124 | 8/21/2026 |
| 10.1.6 | 116 | 8/21/2026 |
| 10.1.5 | 187 | 8/20/2026 |
| 10.1.4 | 114 | 8/20/2026 |
| 10.1.3 | 121 | 8/19/2026 |
| 10.1.2 | 118 | 8/19/2026 |
| 10.1.1 | 103 | 8/19/2026 |
| 10.0.36 | 105 | 8/18/2026 |