From ABP Sensei
Validates DTOs in ABP Framework v10.4 using Data Annotations, IValidatableObject, FluentValidation, and AbpValidationException for standardized input validation.
How this skill is triggered — by the user, by Claude, or both
Slash command
/abp-sensei:abp-validationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
User asks about validation, DTO validation, FluentValidation, IValidatableObject, validation errors, AbpValidationException, or input validation in ABP Framework.
User asks about validation, DTO validation, FluentValidation, IValidatableObject, validation errors, AbpValidationException, or input validation in ABP Framework.
ABP provides automatic validation for application service inputs using:
Validation errors are automatically caught and returned as standardized error responses.
public class CreateBookDto
{
[Required]
[StringLength(100)]
public string Name { get; set; }
[Required]
[StringLength(1000)]
public string Description { get; set; }
[Range(0, 999.99)]
public decimal Price { get; set; }
}
Required, StringLength, Range, EmailAddress, RegularExpression, MinLength, MaxLengthpublic class CreateBookDto : IValidatableObject
{
public string Name { get; set; }
public decimal Price { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var results = new List<ValidationResult>();
if (Price <= 0)
{
results.Add(new ValidationResult(
"Price must be greater than zero.",
new[] { nameof(Price) }
));
}
if (string.IsNullOrWhiteSpace(Name))
{
results.Add(new ValidationResult(
"Name cannot be empty.",
new[] { nameof(Name) }
));
}
return results;
}
}
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
var myService = validationContext.GetRequiredService<IMyService>();
// Use service for validation logic
// ...
}
Warning: Resolving services in
Validateis possible but not recommended. Keep DTOs simple — they should transfer data, not contain domain validation logic.
abp add-package Volo.Abp.FluentValidation
Or manually:
dotnet add package Volo.Abp.FluentValidation
Add module dependency:
[DependsOn(typeof(AbpFluentValidationModule))]
public class MyModule : AbpModule { }
public class CreateUpdateBookDtoValidator : AbstractValidator<CreateUpdateBookDto>
{
public CreateUpdateBookDtoValidator()
{
RuleFor(x => x.Name).Length(3, 10);
RuleFor(x => x.Price).ExclusiveBetween(0.0f, 999.0f);
RuleFor(x => x.Description).NotEmpty().MaximumLength(1000);
}
}
Enable validation on any DI-registered service:
public class MyService : ITransientDependency, IValidationEnabled
{
public virtual async Task DoItAsync(MyInput input)
{
// input is automatically validated
}
}
Requirements:
virtual OR service used via interfaceITransientDependency, ISingletonDependency, or IScopedDependency)public class MyService : ITransientDependency, IValidationEnabled
{
public bool IsValidationEnabled { get; set; } = true; // Default
public virtual async Task DoItAsync(MyInput input) { }
}
Thrown automatically when validation fails:
public class AbpValidationException : AbpException, IHasValidationErrors
{
public IList<ValidationResult> ValidationErrors { get; }
}
IHasValidationErrors — errors serialized in API response{
"error": {
"code": "App:010046",
"message": "Your request is not valid, please correct and try again!",
"validationErrors": [
{
"message": "Username should be minimum length of 3.",
"members": ["userName"]
},
{
"message": "Password is required",
"members": ["password"]
}
]
}
}
Client Request
↓
DTO Deserialization
↓
ABP Validation Interceptor
↓ (if invalid)
AbpValidationException thrown
↓
ABP Exception Handler
↓
HTTP 400 + validationErrors JSON
↓
Client receives structured error
| Attribute | Purpose | Example |
|---|---|---|
[Required] | Non-null, non-empty | [Required] public string Name { get; set; } |
[StringLength(max)] | Max length | [StringLength(100)] |
[StringLength(min, max)] | Min/max length | [StringLength(3, 100)] |
[Range(min, max)] | Numeric range | [Range(0, 999.99)] |
[EmailAddress] | Email format | [EmailAddress] |
[RegularExpression(pattern)] | Regex match | [RegularExpression(@"^[a-zA-Z]+$")] |
[MinLength(n)] | Minimum collection/string length | [MinLength(3)] |
[MaxLength(n)] | Maximum collection/string length | [MaxLength(100)] |
[Url] | URL format | [Url] |
[Phone] | Phone format | [Phone] |
npx claudepluginhub burakdmir/abp-skills --plugin abp-senseiProvides CDSS development patterns for drug interaction checking, dose validation, clinical scoring (NEWS2, qSOFA), and alert classification integrated into EMR workflows.