Repository navigation
value objects
The term Value Object (VO for short) has a specific meaning in DDD parlance: it encapsulates a set of values that are immutable, constant, and never shared elsewhere. VOs are always part of another Aggregate or Entity.
A value object is defined by implementing the IValueObject interface:
using Envivo.Fresnel.ModelTypes.Structural;
using System;
/// <summary>
/// This object is only editable when new, and becomes read-only once it's saved.
/// </summary>
public class Payment : IValueObject //👈
{
[Key]
public Guid Id { get; init; }
[DataType(DataType.Date)]
public DateTime PaymentDate { get; set; } = DateTime.Now;
public decimal Amount { get; set; } = new();
public string OtherNotes { get; set; }
public override string ToString()
{
return $"{PaymentDate:d} : {Amount:c}";
}
}When VOs are created in the UI, they are immediately editable:

Once their parent object is saved to the persistence store, they become read-only:

Value Objects indeed do not need identity. However, they do need to be tracked and persisted to a repository. Fresnel needs the Id property to track the VO internally (it's a leaky abstraction).
The decision of "do I need a Value Object" depends on how that object is used in the domain. For example, an "Address" may be a Value Object in one domain, but could be an Entity in a different domain.
If your object fits one of the following, it's probably a good candidate:
- Super primitives (ie classes that reduce the Primitive Obsession anti-pattern)
- Memento Pattern
- Tokens
Value Objects rarely contain references to Aggregates or Entities. If you do need to reference them, consider using Aggregate References (which are Value Objects in their own right).
Copyright © 2022-2026 Envivo Software
-
Objects
-
Configuring your Model
-
Testing your model
-
Other features