Repository : You shouldn't have a behaviour in your repository
DDD
Except for Anti-Corruption Layer, all behaviours about update data from repository should be in domain (service, Entity, Value Object).
Violations should be raised in case a class with a name ending with "Repository" contains anywhere in the code a "if" or "switch" instruction.
Examples
Example 1:
Negative
Incorrect implementation that violates the practice.
namespace Practices.DDD.Repository.Behaviour
{
public class OrderRepository
{
public Order GetOrder(int orderId)
{
var data = GetData(orderId);
if (data == null)
{
return null;
}
//LastUpdate is a behaviour
//Name toUpper is a behaviour
return new Order() { Id = orderId, Name = data.Name.ToUpper(), LastUpdateDatetime = DateTime.Now };
}
private DataOrder GetData(int orderId)
{
//Get Data from base
return new DataOrder() { Name = "Data" };
}
}
}