Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

DDD Building Blocks

Marc Wittke edited this page Sep 29, 2018 · 1 revision

Aggregate Root

From Wikipedia:

A collection of objects that are bound together by a root entity, otherwise known as an aggregate root. The aggregate root guarantees the consistency of changes being made within the aggregate by forbidding external objects from holding references to its members.

Example: When you drive a car, you do not have to worry about moving the wheels forward, making the engine combust with spark and fuel, etc.; you are simply driving the car. In this context, the car is an aggregate of several other objects and serves as the aggregate root to all of the other systems. The root of one or many objects logically bound together. The aggregate boundary also acts as consistency boundary.

The Backend.Fx base implementation derives from Entity. An AggregateRoot is also referencing a TenantId to enable multi tenancy.

Entity

From Wikipedia:

An object that is not defined by its attributes, but rather by a thread of continuity and its identity.

Example: Most airlines distinguish each seat uniquely on every flight. Each seat is an entity in this context. However, Southwest Airlines, EasyJet and Ryanair do not distinguish between every seat; all seats are the same. In this context, a seat is actually a value object.

The Backend.Fx base implementation derives from Identified. Therefore you get an integer typed key named Id. In addition, all Entities provide basic tracking properties like CreatedOn, CreatedBy. ChangedOn, ChangedBy. Since entities are not to be retrieved without the corresponding AggregateRoot, there is no reference to TenantId. This reference is logically inherited from the corresponding AggregateRoot.

Identified

Something that can be identified by an Id value. In addition to all Entities this could also be a projected shape of an Entity, e.g. provided by a database view. IEquatable<Identitified> is fully implemented, as well as proper overrides of Equals(object other), GetHashCode() and ==/!= operators

Value Object

From Wikipedia:

An object that contains attributes but has no conceptual identity. They should be treated as immutable.

Example: When people exchange business cards, they generally do not distinguish between each unique card; they only are concerned about the information printed on the card. In this context, business cards are value objects.

Repository

From Wikipedia:

Methods for retrieving domain objects should delegate to a specialized Repository object such that alternative storage implementations may be easily interchanged.

An abstract implementation Repository provides multi tenancy support and authorization. Any exception that is caused by wrong data or insufficient privileges are reported by respective specializations of ClientException, e.g. NotFoundException or UnauthorizedException.

IDomainService and IApplicationService

These interfaces serve as marker interfaces to enable auto wiring using a dependency injection container.

Clone this wiki locally