I am trying to figure out how to keep the invariants still consistent for a few consumers (business clients) of the project who have their own requirements on the same version of the aggregate root. Let's take the Customer as an example and ask hypothetical question to meet the following silly logic:
public class Customer
{
public Id { get; private set;}
public string Name { get; private set;}
public void SetName(string name){
//client1 -> requires the name not to be null
//client2 -> requires the name can start with "J"
//client3 -> some other business logic
this.Name = name;
}
}
For now, what I have in mind is having the custom validation/invariant check strategy logic like so:
public void SetName(string name, INameCheckStrategy strategy){
if(!strategy.IsSatisfiedBy(name)) throw new BusinessException("name does not meet the invariant check!");
this.Name = name;
}
where
public class Client1NameCheckStrategy : INameCheckStrategy {
public bool IsSatisfiedBy(string name){
return name != null;
}
}
Any ideas how to handle such problem ?