도메인 서비스 - Domain Services
설명
IDomainService 인터페이스 및 DomainService 클래스
예제
public interface ILunchService : IDomainService
{
void AssignLunchToMeal(Lunch lunch, Meal meal);
}public class LunchService : DomainService, ILunchService
{
public const int MaxLunchCount = 1;
private readonly ITaskRepository _taskRepository;
public TaskManager(ITaskRepository taskRepository)
{
_taskRepository = taskRepository;
}
public void AssignLunchToMeal(Lunch lunch, Meal meal)
{
// 활성상태가 아니면 에러 발생
if (task.State != TaskState.Active)
{
throw new ApplicationException("점심을 먹었습니다.");
}
// 허용된 활성된 숫자인지 체크
if (HasLunchMaximumAssignedMeal(meal))
{
// 오버가 되면 에러 발생
throw new UserFriendlyException(L("점심을 이미 먹었습니다..", meal.Name));
}
}
// 규칙에 맞는지 체크한다
private bool HasPersonMaximumAssignedTask(Meal meal)
{
return assignedTaskCount >= MaxActiveTaskCountForSample;
}
}

Last updated