Repository navigation
consistency checks
vijay@envivo edited this page May 21, 2026
·
8 revisions
Consistency Checks determine if an Entity (or Aggregate Root) is valid before it is persisted (via a Repository). Much like specifications, these let you encapsulate a series of checks into a cohesive domain concept.
To create one, implement the IConsistencyCheck<T> interface:
using Envivo.Fresnel.ModelTypes.Rules;
/// <summary>
/// Checks that Products are consistent, before being saved
/// </summary>
public class ProductConsistencyCheck : IConsistencyCheck<Product> //👈
{
public Assertion Check(Product product)
{
var allExceptions = new List<Exception>();
if (string.IsNullOrEmpty(product.Name))
{
var error = new ValidationException("Name must be provided");
allExceptions.Add(error);
}
if (!product.Categories.Any())
{
var error = new ValidationException("At least 1 Category must be assigned");
allExceptions.Add(error);
}
return allExceptions.Any() ?
Assertion.Fail(allExceptions) :
Assertion.Pass;
}
}If Fresnel finds a consistency check that matches the type of object being saved, it will invoke the check immediately - there is no need to call it explicitly.
Copyright © 2022-2026 Envivo Software
-
Objects
-
Configuring your Model
-
Testing your model
-
Other features