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
                    
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="DKNet.EfCore.Events" Version="9.0.20" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DKNet.EfCore.Events" Version="9.0.20" />
                    
Directory.Packages.props
<PackageReference Include="DKNet.EfCore.Events" />
                    
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 DKNet.EfCore.Events --version 9.0.20
                    
#r "nuget: DKNet.EfCore.Events, 9.0.20"
                    
#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 DKNet.EfCore.Events@9.0.20
                    
#: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=DKNet.EfCore.Events&version=9.0.20
                    
Install as a Cake Addin
#tool nuget:?package=DKNet.EfCore.Events&version=9.0.20
                    
Install as a Cake Tool

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, or onDelete).
  • 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

  1. 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" />
    
  2. Implement IEventEntity

    Use IEventEntity to add events to entities:

    public class MyDomainEntity : IEventEntity
    {
        // Implement business logic that triggers AddEvent calls.
    }
    
  3. Register Event Handlers

    Register custom event handlers in your application startup or configuration:

    services.AddScoped<IEventHandler<MyCustomEvent>, CustomEventHandler>();
    
  4. 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:

  1. Check if your entity implements IEventEntity and properly triggers events.
  2. Ensure that your event handlers are registered or decorated correctly.
  3. 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

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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