Fluxera.Entity 8.0.7

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Fluxera.Entity --version 8.0.7
NuGet\Install-Package Fluxera.Entity -Version 8.0.7
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="Fluxera.Entity" Version="8.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fluxera.Entity --version 8.0.7
#r "nuget: Fluxera.Entity, 8.0.7"
#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.
// Install Fluxera.Entity as a Cake Addin
#addin nuget:?package=Fluxera.Entity&version=8.0.7

// Install Fluxera.Entity as a Cake Tool
#tool nuget:?package=Fluxera.Entity&version=8.0.7

Build Status

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.

IDomainEventHandler

A domain event handler of this type will be executed before a Repository adds or updates the entity in the storage.

ICommittedDomainEventHandler

A domain event handler of this type will be executed after a Repository adds or updates the entity in the storage.

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)
	{
		// Do something ...
		return Task.CompletedTask;
	}
}
public class SalaryRaisedEventHandler : ICommittedDomainEventHandler<SalaryRaisedEvent>
{
	public Task HandleAsync(SalaryRaisedEvent domainEvent)
	{
		// Do something ...
		return Task.CompletedTask;
	}
}
// A domain event support.
services.AddDomainEvents(builder =>
{
	builder
		.AddDomainEventHandlers<SalaryRaisedEventHandler>()
		.AddDomainEventHandlers<AdditionalSalaryRaisedEventHandler>()
		.AddDomainEventHandlers<SalaryRaisedCommittedEventHandler>();
});

IDomainEventDispatcher dispatcher = /* Get the dispatcher ... */;

SalaryRaisedEvent salaryRaisedEvent = new SalaryRaisedEvent(100_000);

await dispatcher.DispatchAsync(salaryRaisedEvent);
await dispatcher.DispatchCommittedAsync(salaryRaisedEvent);

References

Jimmy Bogard - A better domain events pattern

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Fluxera.Entity:

Package Downloads
Fluxera.Repository.Abstractions The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

The abstractions for the generic repository implementation.

Fluxera.Repository The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A generic repository implementation.

Fluxera.Extensions.Hosting.Modules.Domain The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A module that enables the domain.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
8.0.7 53 4/18/2024
8.0.6 340 4/13/2024
8.0.5 159 4/13/2024
8.0.4 317 3/19/2024
8.0.3 902 2/22/2024
8.0.2 2,294 1/4/2024
8.0.1 844 11/23/2023
8.0.0 586 11/15/2023
7.1.7 653 7/23/2023
7.1.6 370 7/20/2023
7.1.5 609 6/21/2023
7.1.4 2,455 4/13/2023
7.1.3 952 3/16/2023
7.1.2 1,050 2/27/2023
7.1.1 1,111 1/22/2023
7.1.0 714 1/18/2023
7.0.6 1,853 12/13/2022
7.0.5 1,494 12/9/2022
7.0.4 1,025 11/19/2022
7.0.3 319 11/18/2022
7.0.2 326 11/15/2022
7.0.1 797 11/12/2022
7.0.0 347 11/9/2022
6.1.11 2,199 10/12/2022
6.1.10 7,780 9/15/2022
6.1.9 2,218 7/30/2022
6.1.8 2,249 6/30/2022
6.1.7 2,285 6/15/2022
6.1.6 3,250 6/7/2022
6.1.5 1,475 6/3/2022
6.1.4 2,527 6/1/2022
6.1.3 2,521 5/31/2022
6.1.2 2,240 5/30/2022
6.1.1 3,286 5/29/2022
6.1.0 3,310 5/28/2022
6.0.16 5,272 5/18/2022
6.0.15 3,666 5/5/2022
6.0.14 2,510 4/20/2022
6.0.13 3,429 4/11/2022
6.0.11 4,872 3/24/2022
6.0.10 1,632 2/17/2022
6.0.9 1,090 12/17/2021
6.0.7 355 12/16/2021
6.0.5 453 12/13/2021
6.0.3 434 12/11/2021