DKNet.EfCore.Events
9.0.20
dotnet add package DKNet.EfCore.Events --version 9.0.20
NuGet\Install-Package DKNet.EfCore.Events -Version 9.0.20
<PackageReference Include="DKNet.EfCore.Events" Version="9.0.20" />
<PackageVersion Include="DKNet.EfCore.Events" Version="9.0.20" />
<PackageReference Include="DKNet.EfCore.Events" />
paket add DKNet.EfCore.Events --version 9.0.20
#r "nuget: DKNet.EfCore.Events, 9.0.20"
#:package DKNet.EfCore.Events@9.0.20
#addin nuget:?package=DKNet.EfCore.Events&version=9.0.20
#tool nuget:?package=DKNet.EfCore.Events&version=9.0.20
DKNet.EfCore.Events
DKNet.EfCore.Events
is part of the DKNet suite, designed to enhance Entity Framework Core (EF Core) applications by
providing event-based functionality. This library enables developers to trigger events based on data changes (e.g.,
onCreate
, onUpdate
, or onDelete
) and handle them using custom logic.
Overview
The goal of DKNet.EfCore.Events
is to simplify the implementation of domain-driven design (DDD) principles in EF Core
applications. It provides a centralized way to manage events and their handlers, allowing developers to implement
business rules and validation logic without tightly coupling it with the data access layer.
Key Concepts
EventPublisher: A central hub for publishing events. All events are routed through this publisher.
IEventEntity: An interface that defines methods for adding domain events to a queue and retrieving/clearing them.
Custom Event Handlers: Developers can implement custom handlers to respond to specific events, such as validating data or triggering external services.
Features
1. Event Triggers
- Automatically fire events in response to changes in your data (e.g.,
onCreate
,onUpdate
, oronDelete
). - Events are queued and published through the
IEventPublisher
.
2. Custom Event Handlers
- Write custom handlers to implement specific business logic for any event.
- Handlers can be registered as decorators or directly in your application.
3. Pre & Post Save Actions
- Hook pre-save and post-save actions during database operations.
- Perform validation, data transformation, or external API calls before or after saving changes.
4. Integration with EF Core
- Seamless integration with Entity Framework Core for event-driven database operations.
- Supports both domain events and application-specific events.
How to Use
Add the Package
Include
DKNet.EfCore.Events
in your project by adding the following reference to your.csproj
file:<PackageReference Include="DKNet.EfCore.Events" Version="x.y.z" />
Implement IEventEntity
Use
IEventEntity
to add events to entities:public class MyDomainEntity : IEventEntity { // Implement business logic that triggers AddEvent calls. }
Register Event Handlers
Register custom event handlers in your application startup or configuration:
services.AddScoped<IEventHandler<MyCustomEvent>, CustomEventHandler>();
Publish Events
Use the
IEventPublisher
to publish events:await _eventPublisher.PublishAsync(new MyDomainEvent());
Advanced Usage
Domain Events vs Application Events
- Domain Events: Represent business concepts and are raised by entities (
IEventEntity
). - Application Events: Used for application-level operations, such as sending emails or notifications.
Event Handling Location
- Decorators: Implement handlers as decorators around your domain logic.
- Registered Services: Register handlers directly in your dependency injection container.
Best Practices
- Use events to decouple data changes from the logic that responds to those changes.
- Keep event handlers focused on a single responsibility (e.g., validation, logging).
- Handle errors in event handlers using appropriate error handling strategies.
Troubleshooting
If you encounter issues:
- Check if your entity implements
IEventEntity
and properly triggers events. - Ensure that your event handlers are registered or decorated correctly.
- Verify that the
IEventPublisher
is being injected and used appropriately.
Contributions
Contributions are welcome! Familiarize yourself with the DKNet design principles before making changes. Submit pull requests with detailed explanations of your changes.
License
DKNet.EfCore.Events
is MIT licensed, allowing you to use, modify, and distribute it freely.
References
- EF Core: Microsoft.EntityFrameworkCore
- FluentAssertions: FluentAssertions NuGet Package
Product | Versions 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. |
-
net9.0
- DKNet.EfCore.Abstractions (>= 9.0.20)
- DKNet.EfCore.Hooks (>= 9.0.20)
- FluentResults (>= 4.0.0)
- Mapster (>= 7.4.0)
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 |
---|---|---|
9.0.20 | 138 | 7/15/2025 |
9.0.19 | 136 | 7/14/2025 |
9.0.18 | 137 | 7/14/2025 |
9.0.17 | 135 | 7/14/2025 |
9.0.16 | 118 | 7/11/2025 |
9.0.15 | 119 | 7/11/2025 |
9.0.14 | 117 | 7/11/2025 |
9.0.13 | 126 | 7/11/2025 |
9.0.12 | 145 | 7/8/2025 |
9.0.11 | 140 | 7/8/2025 |
9.0.10 | 135 | 7/7/2025 |
9.0.9 | 137 | 7/2/2025 |
9.0.7 | 142 | 7/1/2025 |
9.0.6 | 141 | 6/30/2025 |
9.0.5 | 138 | 6/24/2025 |
9.0.4 | 138 | 6/24/2025 |
9.0.3 | 143 | 6/23/2025 |
9.0.2 | 139 | 6/23/2025 |
9.0.1 | 148 | 6/23/2025 |