FluentValidation Triggered But No Validation Applied For DTOs in Custom Module
I created a custom module named JobAnnouncement using the ABP Framework and added FluentValidation for my JobCreateDto class. Although the validator is defined correctly and the module depends on AbpFluentValidationModule, the validation is being triggered, but the validation rules are not being applied when I call the application service in the host project.
✅ Validator Code
using FluentValidation;
using JobAnnouncement.App.Jobs.Dtos;
namespace JobAnnouncement.App.Jobs.Validations
{
public class JobCreateDtoValidator : AbstractValidator<JobCreateDto>
{
public JobCreateDtoValidator()
{
RuleFor(x => x.Title).NotNull();
RuleFor(x => x.Description).NotEmpty();
RuleFor(x => x.Requirements).NotEmpty();
RuleFor(x => x.IsActive).NotEmpty();
}
}
}
✅ Module Configuration
public async override Task<JobDto> CreateAsync(JobCreateDto input)
{
// some logic
return await base.CreateAsync(input);
}
✅ Module Configuration
[DependsOn(
typeof(JobAnnouncementDomainModule),
typeof(JobAnnouncementApplicationContractsModule),
typeof(AbpDddApplicationModule),
typeof(AbpAutoMapperModule),
typeof(AbpFluentValidationModule)
)]
public class JobAnnouncementApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAutoMapperObjectMapper<JobAnnouncementApplicationModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<JobAnnouncementApplicationModule>(validate: true);
});
}
}
What I’ve Tried The validator class is public and inherits from AbstractValidator<JobCreateDto>.
I added AbpFluentValidationModule in the [DependsOn] attribute in my module.
The module is properly referenced and loaded in the host application.
❌ Issue Validation does not run — even when required fields are missing, no validation error or exception is triggered. The CreateAsync method accepts invalid data without any validation feedback.
hi
Please share a project to reproduce the problem.
Thanks.
Hi @maliming
Thanks for your response. You can find the project to reproduce the issue here: https://github.com/Ramiii0/XHost
Please let me know if you need any additional details.
hi
What are the steps to reproduce?
Thanks.
Hi,
To reproduce the issue:
- Clone and run the XHost solution.
- Send a POST request to
/api/app/gamewith any of the following payloads:
{
"title": "A"
}
or
{
"title": ""
}
Validation Rule:
RuleFor(x => x.Title)
.NotEmpty()
.Length(3, 10);
what happens:
- The validation does not apply — even when the
titleis just one character or only spaces. - The request is processed as if the input were valid.
Let me know if you need anything else.
Thanks!
hi
Try to add IGameAppService controller in XModule.HttpApi project instead of options.ConventionalControllers.Create(typeof(XModuleApplicationModule).Assembly);
Same as https://github.com/Ramiii0/XHost/blob/master/modules/src/XModule.HttpApi/Samples/ExampleController.cs#L8-L33
The Types in ConventionalControllers will disable Interceptor.