Fluxera.Entity
9.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Fluxera.Entity --version 9.0.0
NuGet\Install-Package Fluxera.Entity -Version 9.0.0
<PackageReference Include="Fluxera.Entity" Version="9.0.0" />
paket add Fluxera.Entity --version 9.0.0
#r "nuget: Fluxera.Entity, 9.0.0"
// Install Fluxera.Entity as a Cake Addin #addin nuget:?package=Fluxera.Entity&version=9.0.0 // Install Fluxera.Entity as a Cake Tool #tool nuget:?package=Fluxera.Entity&version=9.0.0
Fluxera.Entity
An aggregate root and entity objects library.
This library helps in implementing Entity, Aggregate Root and Domain Events. The base class for entities implement Equality and Uniqueness based on selected attributes of the entity instead of the references.
Equality and Uniqueness
The equality check consist of two major steps:
1.) When comparing two entities for Equality at first we check if the entites are both not transient and their IDs are equal. In this case the entites are considered equal, even if their values are different.
2.) If the first step did not signal Equality we check if the entities are both transient
and their domain signature attributes are equal. You define which attributes of the entity make
up their domain signature by adding the [DomainSignature]
attribute to the corresponding
properties. The attributes are then picked up by the default implementation using reflection.
If you do not want to use the default implementation you can override the GetEqualityComponents()
method an return the values to use manually.
Domain Events
This library provides the infrastructure to implement, register and dispatch domain events from
entities to loosely-coupled domain event handlers. You can add events to the DomainEvents
collection of an entity and implement two different types of domain event handlers for it.
This library provides the nessessary dispatcher service which can be used to integrate the event
dispatching in a Repository implementation. A IDomainEventHandler
implementation handles
a published domain event.
Configuration
Two different publishing infrastructures exist:
A default implementation using a custom domain event dispatcher.
- Add the
Fluxera.DomainEvents
package to use this implementation.
- Add the
A MediatR based implementation using the
IPublisher
of the MediatR library.- Add the
Fluxera.DomainEvents.MediatR
package to use this implementation.
- Add the
You can NOT use both packages at the same time.
Default implementation (Fluxera.DomainEvents
)
// A domain event support.
services.AddDomainEvents();
// Add domain event handlers.
services.AddDomainEventHandler<SalaryRaisedEventHandler>();
IDomainEventDispatcher dispatcher = /* Get the dispatcher ... */;
SalaryRaisedEvent salaryRaisedEvent = new SalaryRaisedEvent(100_000);
await dispatcher.DispatchAsync(salaryRaisedEvent);
MediatR implementation (Fluxera.DomainEvents.MediatR
)
// A domain event support.
services.AddDomainEvents();
// Add domain event handlers by configuring MediatR.
// This will automatically register all domain event handlers in the given assembly.
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly());
});
IDomainEventDispatcher dispatcher = /* Get the dispatcher ... */;
SalaryRaisedEvent salaryRaisedEvent = new SalaryRaisedEvent(100_000);
await dispatcher.DispatchAsync(salaryRaisedEvent);
Usage
public class Employee : AggregateRoot<Employee>
{
[DomainSignature]
public string Name { get; set; }
[DomainSignature]
public int EmployeeNumber { get; set; }
public decimal Salary { get; set; }
public void GiveRaise(decimal raiseAmount)
{
Guard.Against.NegativeOrZero(raiseAmount, nameof(raiseAmount));
this.Salary += raiseAmount;
this.DomainEvents.Add(new SalaryRaisedEvent(this.Salary));
}
}
public class SalaryRaisedEvent : IDomainEvent
{
public SalaryRaisedEvent(decimal newSalary)
{
this.NewSalary = newSalary;
this.HandlerNames = new List<string>();
}
public decimal NewSalary { get; }
}
public class SalaryRaisedEventHandler : IDomainEventHandler<SalaryRaisedEvent>
{
public Task HandleAsync(SalaryRaisedEvent domainEvent, CancellationToken cancellationToken = default)
{
// Do something ...
return Task.CompletedTask;
}
}
Future
With the upcoming v9.0 release in november 2024 the domain events libraries will be moved to a separate repository, because it can be used with your own entities and repositories.
References
Jimmy Bogard - A better domain events pattern
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 is compatible. |
-
net8.0
- Fluxera.DomainEvents.Abstractions (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (= 8.0.1)
-
net9.0
- Fluxera.DomainEvents.Abstractions (>= 9.0.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Fluxera.Entity:
Package | Downloads |
---|---|
Fluxera.Repository.Abstractions
The abstractions for the generic repository implementation. |
|
Fluxera.Repository
A generic repository implementation. |
|
Fluxera.Extensions.Hosting.Modules.Domain
A module that enables the domain. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.1 | 241 | 11/16/2024 |
9.0.0 | 126 | 11/14/2024 |
8.3.4 | 403 | 11/1/2024 |
8.3.3 | 95 | 7/9/2024 |
8.3.2 | 1,002 | 6/12/2024 |
8.3.1 | 208 | 6/8/2024 |
8.3.0 | 684 | 5/26/2024 |
8.2.1 | 110 | 5/24/2024 |
8.2.0 | 554 | 4/28/2024 |
8.1.2 | 1,118 | 4/25/2024 |
8.1.1 | 104 | 4/25/2024 |
8.1.0 | 119 | 4/25/2024 |
8.0.7 | 1,648 | 4/18/2024 |
8.0.6 | 727 | 4/13/2024 |
8.0.5 | 245 | 4/13/2024 |
8.0.4 | 453 | 3/19/2024 |
8.0.3 | 1,229 | 2/22/2024 |
8.0.2 | 2,920 | 1/4/2024 |
8.0.1 | 1,001 | 11/23/2023 |
8.0.0 | 783 | 11/15/2023 |
7.1.7 | 776 | 7/23/2023 |
7.1.6 | 427 | 7/20/2023 |
7.1.5 | 718 | 6/21/2023 |
7.1.4 | 2,845 | 4/13/2023 |
7.1.3 | 1,082 | 3/16/2023 |
7.1.2 | 1,214 | 2/27/2023 |
7.1.1 | 1,260 | 1/22/2023 |
7.1.0 | 816 | 1/18/2023 |
7.0.6 | 2,151 | 12/13/2022 |
7.0.5 | 1,704 | 12/9/2022 |
7.0.4 | 1,134 | 11/19/2022 |
7.0.3 | 346 | 11/18/2022 |
7.0.2 | 354 | 11/15/2022 |
7.0.1 | 859 | 11/12/2022 |
7.0.0 | 377 | 11/9/2022 |
6.1.11 | 2,308 | 10/12/2022 |
6.1.10 | 8,142 | 9/15/2022 |
6.1.9 | 2,331 | 7/30/2022 |
6.1.8 | 2,372 | 6/30/2022 |
6.1.7 | 2,381 | 6/15/2022 |
6.1.6 | 3,388 | 6/7/2022 |
6.1.5 | 1,539 | 6/3/2022 |
6.1.4 | 2,621 | 6/1/2022 |
6.1.3 | 2,620 | 5/31/2022 |
6.1.2 | 2,334 | 5/30/2022 |
6.1.1 | 3,426 | 5/29/2022 |
6.1.0 | 3,433 | 5/28/2022 |
6.0.16 | 5,524 | 5/18/2022 |
6.0.15 | 3,817 | 5/5/2022 |
6.0.14 | 2,611 | 4/20/2022 |
6.0.13 | 3,564 | 4/11/2022 |
6.0.11 | 5,051 | 3/24/2022 |
6.0.10 | 1,705 | 2/17/2022 |
6.0.9 | 1,168 | 12/17/2021 |
6.0.7 | 380 | 12/16/2021 |
6.0.5 | 478 | 12/13/2021 |
6.0.3 | 462 | 12/11/2021 |