For years I’ve struggled with how to handle very simple validation scenarios.
Most systems have identifiers with basic constraints — fixed length, allowed characters, or formatting rules. The problem usually isn’t writing the validation itself, but deciding where that validation should live and ensuring it’s applied consistently.
Consider a simple example: suppose our application models an Order, and the system requires that an order ID must be exactly 10 characters long.
For a long time I would have implemented it like this:
public class Order
{
public string Id { get; set; } = string.Empty;
}
Nothing unusual there. Also, until fairly recently I would typically enforce validation using a separate validator:
public class OrderValidator
{
public void Validate(Order order)
{
ArgumentNullException.ThrowIfNull(order);
ArgumentException.ThrowIfNullOrWhiteSpace(order.Id);
if (order.Id.Trim().Length != 10)
{
thro
Discussion
Don’t hold back—comment!
Don’t wait—start sharing your ideas now!