using Hutopy.Application.Common.Interfaces; namespace Hutopy.Application.TodoLists.Commands.CreateTodoList; public class CreateTodoListCommandValidator : AbstractValidator { private readonly IApplicationDbContext _context; public CreateTodoListCommandValidator(IApplicationDbContext context) { _context = context; RuleFor(v => v.Title) .NotEmpty() .MaximumLength(200) .MustAsync(BeUniqueTitle) .WithMessage("'{PropertyName}' must be unique.") .WithErrorCode("Unique"); } public async Task BeUniqueTitle(string title, CancellationToken cancellationToken) { return await _context.TodoLists .AllAsync(l => l.Title != title, cancellationToken); } }