fluentvalidation-patterns
БесплатноБез исполняемых скриптовНе проверенMaster FluentValidation patterns for ABP Framework including async validators, repository checks, conditional rules, localized messages, and custom…
Об этом скилле
FluentValidation Patterns
FluentValidation patterns for ABP Framework input DTO validation.
When to Use
- Creating validators for Create/Update DTOs
- Implementing async validation with repository checks
- Building conditional validation rules
- Creating reusable custom validators
- Localizing validation error messages
ABP Integration
Basic Validator Structure
// Application/{Feature}/CreateUpdate{Entity}DtoValidator.cs
public class CreateUpdate{Entity}DtoValidator : AbstractValidator<CreateUpdate{Entity}Dto>
{
public CreateUpdatePatientDtoValidator()
{
RuleFor(x => x.FirstName)
.NotEmpty()
.MaximumLength(100);
RuleFor(x => x.LastName)
.NotEmpty()
.MaximumLength(100);
RuleFor(x => x.Email)
.NotEmpty()
.EmailAddress()
.MaximumLength(255);
RuleFor(x => x.DateOfBirth)
.NotEmpty()
.LessThan(DateTime.Today)
.WithMessage("Date of birth must be in the past");
}
}
ABP Module Registration
// ApplicationModule.cs
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpFluentValidationAutoValidationOptions>(options =>
{
options.AutoValidateMethodInvocations = true;
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
// Auto-register all validators in assembly
context.Services.AddValidatorsFromAssembly(typeof({ProjectName}ApplicationModule).Assembly);
}
Common Validation Rules
String Validation
RuleFor(x => x.Name)
.NotEmpty()
.WithMessage("Name is required")
.MinimumLength(2)
.MaximumLength(100)
.Matches(@"^[a-zA-Z\s]+$")
.WithMessage("Name can only contain letters and spaces");
RuleFor(x => x.Email)
.NotEmpty()
.EmailAddress()
.Must(email => !email.EndsWith("@test.com"))
.WithMessage("Test emails are not allowed");
RuleFor(x => x.Phone)
.NotEmpty()
.Matches(@"^\+?[1-9]\d{1,14}$")
.WithMessage("Invalid phone number format");
Numeric Validation
RuleFor(x => x.Age)
.InclusiveBetween(0, 150)
.WithMessage("Age must be between 0 and 150");
RuleFor(x => x.Price)
.GreaterThan(0)
.LessThanOrEqualTo(1000000)
.PrecisionScale(10, 2, false);
RuleFor(x => x.Quantity)
.GreaterThanOrEqualTo(1)
.When(x => x.IsRequired);
Date Validation
RuleFor(x => x.DateOfBirth)
.NotEmpty()
.LessThan(DateTime.Today)
.GreaterThan(DateTime.Today.AddYears(-150));
RuleFor(x => x.AppointmentDate)
.NotEmpty()
.GreaterThan(DateTime.Now)
.WithMessage("Appointment must be in the future");
RuleFor(x => x.EndDate)
.GreaterThan(x => x.StartDate)
.When(x => x.EndDate.HasValue)
.WithMessage("End date must be after start date");
Collection Validation
RuleFor(x => x.Tags)
.NotEmpty()
.Must(tags => tags.Count <= 10)
.WithMessage("Maximum 10 tags allowed");
RuleForEach(x => x.Items)
.ChildRules(item =>
{
item.RuleFor(i => i.ProductId).NotEmpty();
item.RuleFor(i => i.Quantity).GreaterThan(0);
});
RuleFor(x => x.Emails)
.Must(emails => emails.Distinct().Count() == emails.Count)
.WithMessage("Duplicate emails are not allowed");
Async Validation with Repository
Unique Email Check
public class CreateUpdate{Entity}DtoValidator : AbstractValidator<CreateUpdate{Entity}Dto>
{
private readonly IRepository<{Entity}, Guid> _repository;
public CreateUpdate{Entity}DtoValidator(IRepository<{Entity}, Guid> repository)
{
_repository = repository;
RuleFor(x => x.Email)
.NotEmpty()
.EmailAddress()
.MustAsync(BeUniqueEmail)
.WithMessage("Email already exists");
}
private async Task<bool> BeUniqueEmail(string email, CancellationToken cancellationToken)
{
return !await _repository.AnyAsync(e => e.Email == email);
}
}
Unique Check with Edit Context
public class CreateUpdate{Entity}DtoValidator : AbstractValidator<CreateUpdate{Entity}Dto>
{
private readonly IRepository<{Entity}, Guid> _repository;
private readonly IHttpContextAccessor _httpContextAccessor;
public CreateUpdate{Entity}DtoValidator(
IRepository<{Entity}, Guid> repository,
IHttpContextAccessor httpContextAccessor)
{
_repository = repository;
_httpContextAccessor = httpContextAccessor;
RuleFor(x => x.Email)
.NotEmpty()
.EmailAddress()
.MustAsync(BeUniqueEmailAsync)
.WithMessage("Email already exists");
}
private async Task<bool> BeUniqueEmailAsync(string email, CancellationToken cancellationToken)
{
// Get entity ID from route (for updates)
var routeData = _httpContextAccessor.HttpContext?.
Установить fluentvalidation-patterns в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл fluentvalidation-patterns?
Master FluentValidation patterns for ABP Framework including async validators, repository checks, conditional rules, localized messages, and custom validators. Use when creating input DTO validators for AppServices.
Как установить скилл fluentvalidation-patterns?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fluentvalidation-patterns запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic