Questions tagged [fluentvalidation]

Fluent Validation is an ASP.NET MVC integrated validation framework that allows the developer to set validation rules using expressions. It is testable and completely compatible with the inversion of control (dependency injection) pattern and TDD (test-driven development) technique.

Filter by
Sorted by
Tagged with
0 votes
0 answers
33 views

FluentValidation - returns default response when object is NULL

I hope you are well. I have a question to ask you. There is an architecture I use for a project. I'm using fluentvalidation on the server side. I have no problems with all the validations I use, but ...
OsKyy's user avatar
  • 33
0 votes
1 answer
18 views

How to Run FluentValidation Before Authorization Filter in ASP.NET Core

I am working on an ASP.NET Core project where I'm using FluentValidation for DTO validation and have also implemented custom authorization filters. Currently, I'm facing a challenge where the ...
esege's user avatar
  • 61
0 votes
1 answer
21 views

With FluentValidation, get the index of the wrong elements

With FluentValidation, I'm trying to get the index of the invalid element in the list but I only get the error from the RuleFor. RuleForEach(m => m.Attendees) .OverrideIndexer((_, _, element, _) =...
Vincent's user avatar
  • 510
1 vote
1 answer
54 views

Fluent Validator in Blazor - Trigger Validation After Component Value Update

This question is regarding a Blazor Server Application using the Blazor Fluent Validation package. I have created a component that is effectively a numeric text box field that enforces values to be ...
bruceiow's user avatar
0 votes
1 answer
39 views

Fluent Validation rules not returning the correct error code

Using Fluent Validation, I want to validate the following class: public class Saloon { public SaloonTypeEnum SaloonType { get; set; } public Percentage2TypeEnum? Percentage2Type { get; set; } ...
Nice Kloe's user avatar
3 votes
2 answers
103 views

Validation within nested Blazor components

I am designing a component in Blazor (.net 8) which contains a number of child components. See the image below: The CreateBill component is the main container There are 3 instances of the Contact ...
Killnine's user avatar
  • 5,658
0 votes
0 answers
24 views

How to add FluentValidationRules To Swagger in ABP Framework

I want to add Validation rules to Swagger to see them in schema like in the screen. I tried to use library MicroElements.Swashbuckle.FluentValidation. But I guess it does not support ...
EXD's user avatar
  • 1
0 votes
1 answer
51 views

I can't cast Exception to ValidationException in error handling middleware

I need some help in regards of exception handling middleware in ASP.NET Core. I am using Fluent Validation to validate the input from user in a Pipeline with MediatR, the exception that gets thrown is ...
RidingBoi's user avatar
-1 votes
0 answers
30 views

Problem in showing Fluent Validation Errors in View

i want to see the Fluent Validation errors just under the input boxes (i've tried using and submit button method and it was correct) but i need to do it in another way. my entity code: public class ...
Magasvazn's user avatar
0 votes
0 answers
26 views

Fluent UI React - Date Picker Validation styling

I want to add validation to my date picker, as shown in the image below. It is a field inside a form. I want to validate on submit button click. I can write the custom logic to validate the field, but ...
Satya's user avatar
  • 25
0 votes
1 answer
28 views

FluentValidation custom validator with dependent rules

I want to have a custom validator for various fields that have specific validation rules, so I don't have to duplicate code. For this example, I want one for an email field. I have validation helper ...
Robin's user avatar
  • 2,714
1 vote
1 answer
87 views

Validate IOptions<T> on start, Without using Bind to read from configuration

SDK: .NET 8 RC4 I want to validate my options at the start. So I added this in my Program.cs builder.Services .AddOptionsWithValidateOnStart<SMTPOptions>() .Bind(builder.Configuration....
Alen Smith's user avatar
  • 1,419
0 votes
1 answer
36 views

FluentValidation wrong response via MediatR pipeline

I am using this ValidationBehavior class: public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse> { ...
defcon1's user avatar
  • 27
1 vote
0 answers
30 views

FluentValidation - with AutoValidation, how to not throw an exception in certain cases

We're using FluentValidation 11.7.1 and FluentValidation.AspNetCore 11.3.0 in our .net 7 web api project to validate all incoming requests. We're still using the auto-validation, and have it ...
BrianS's user avatar
  • 41
1 vote
1 answer
63 views

How to set up validation for nested objects using FluentValidation

I'm using FluentValidation in my API, and I've created four validators. The first one is for order level validation, the second one is for order detail level validation, and the other two are for ...
DDNL's user avatar
  • 13
1 vote
2 answers
83 views

Fluent validator with minimal api endpoint never gets executed

I'm trying to implement fluent validation extension on minimal api endpoint project but I cannot manage to make it work the project is .net 7 version with <PackageReference Include="O9d....
user1765862's user avatar
  • 13.7k
0 votes
0 answers
47 views

FluentValidation set validator if condition is true

I'm trying to get my validator to only validate a complex child property providing that one of the properties in the parent object is true. In my view model I have: public class PersonDetailsViewModel ...
KTOV's user avatar
  • 626
0 votes
2 answers
41 views

Validate Nullable Enum Values using Fluent Validation

I have a nullable list of Enumeration and I would like to validate the enum only if the list is NOT null. I do see option to validate for Null & IsInEnum. But would like to do only if the ...
user007's user avatar
  • 1,546
2 votes
2 answers
62 views

Cannot get IValidator<T> of FastEndpoint validator instance from ServiceProvider in ISchemaFilter

I am using FastEndpoint to perfom some validations in requests, so, I need to obtain a instance of IValidator<T> in order to get its properties using reflection but it returns null for some ...
Jorge Zapata's user avatar
0 votes
1 answer
30 views

FluentValidation - allow empty value for exact index in array

I'm using FluentValidation to Validate my form. I have a input field which is string[] up to 5 elements long and I need to Validate that Input to require Elements[1][2][3] values to be NotEmpty(), ...
CraneDev's user avatar
0 votes
1 answer
36 views

Strategy validation searching criteria. FluentValidation .NET Core

I have a problem with object validation in my ASP.NET Core 6 Web API with FluentValidation. I have criteria objects with many properties, and some rules with a combination of properties to start a ...
Daniel K's user avatar
0 votes
1 answer
29 views

How can I avoid repeated retrieval of data from the database in Fluent Validation?

In my project I use Fluent Validation to define custom validation rules. I have noticed that in many of my validation rules, it is necessary to retrieve a value from a database to perform the ...
Giulia Meo's user avatar
1 vote
1 answer
93 views

Can FluentValidation be used/combined with the railway style pattern of programming?

I've been using FluentValidation for a quite a while and it serves its use quite well. I am currently converting a project from .Net 4.8 to .Net Core 6.0, and I also updated the code to work with the ...
boggy's user avatar
  • 3,752
0 votes
2 answers
118 views

Fluent Validation - How to remove default error message

I have a project with .NET 7 and try using Fluent Validation. My validation is as below: RuleFor(x => x.Number) .Cascade(CascadeMode.Stop) .Must((model, number, context) => { var (isValid, ...
mth12's user avatar
  • 15
0 votes
0 answers
26 views

XUnit Test of Validator (FluentValidation): Way to Force Invalid DTO Instantiation?

I am generating unit tests for my validators built using Fluent Validation. I want to simulate instances that I expect to receive from poorly formed incoming DTOs (such as null values, or bad enums). ...
Brice's user avatar
  • 21
0 votes
0 answers
19 views

How to use CallBase method on mocked Fluentvalidation Validator using Moq

The goal is to verify wether the validation was invoked using the right ruleset whilst still invoking the actual validation (base method). The current implementation gives a DynamicProxy2 exception ...
MichielDeRouter's user avatar
0 votes
1 answer
60 views

FluentValidation SetValidator not called when property is null

I have a few custom validators that I attach to fields using the RuleFor(o => o.property).SetValidator(new CustomValidator()) syntax. Here is an example: public class BankRoutingNumberValidator : ...
BJ Safdie's user avatar
  • 3,411
1 vote
0 answers
34 views

How to implement generic ValidationBehavion using MediatR and FluentValidation so that the ValidationBehavion only triggers on commands

I'm using CQRS and to separate commands and queries I created custom interfaces, so I want my ValidationBehavion to trigger only on the custom ICommand<TResponse> inheriting IRequest<...
Maks0s's user avatar
  • 11
1 vote
0 answers
38 views

How to extend validation rule only for some RuleSets

I have a property of the model that must always follow some constraints. In case of some actions (e.g. adding) it must also create a unique key. I see no way without duplicating the basic rule to ...
Bartosz Domżalski's user avatar
0 votes
1 answer
37 views

Add custom state during custom validation

I created a custom validation rule in FluentValidation, but I am unable to figure out how to add a custom state to the error: RuleFor(x => x.MyField).Custom((myField, context) => { switch (...
stefan.at.kotlin's user avatar
0 votes
0 answers
51 views

Conditional validation in FluentValidation / switch like

I need some type of conditional validation in FluetValidation, like a switch statement. I've seen there is When and Otherwise in FluentValidation, but that would give me roughly 10 or more nested When/...
stefan.at.kotlin's user avatar
1 vote
1 answer
60 views

Combine multiple FluentValidation conditions with or?

I have a property where I want to check if it is either empty or in a specific format. I know I could put both conditions in one regex, but using something like Empty().Or.Matches(...) would be far ...
stefan.at.kotlin's user avatar
0 votes
0 answers
57 views

FluentValidation messages come in different languages ​and the message is not reflected on the screen

I am using FluentValidation in my project. I use WithMessage in the definition, but the message I use is not displayed. Although I write a message in Turkish, an English expression appears on the ...
Gökmen ADA's user avatar
0 votes
0 answers
20 views

Assert that a Mocked Validator has been processed

I'm trying to test FluentValidation validators with inheritance in the models. Basically, I have a validator that applies some rules, before calling the parent class's validator for other rules. The ...
Titouan L's user avatar
  • 1,202
1 vote
1 answer
34 views

Should FluentValidation consists database connection [closed]

I have a validation in controller when user wants to create new account with classic dto model (Nickname, Email, Password). I use Fluent Validation for checking for example if password is not null and ...
JakubCzura's user avatar
0 votes
1 answer
75 views

Fluent Validation CascadeMode.Stop doesnt work on childrules

Validator class like below and it is FluentValidation 9.3.0. I want to return first failure message from this code block but every time it returns all failure messages. I didnt see any example in ...
Unknown Artist's user avatar
0 votes
0 answers
62 views

Mediator IPipeline not registered in ASP.NET Core

I am trying to create a validation pipeline with mediator and fluent validation in ASP.NET, but the file is seem to me is not registered, so I need some help. This is my validation pipeline: using ...
Ali hmaidi's user avatar
0 votes
0 answers
36 views

I can't see error validation messages when using Fluent Validation

I am using Fluent Validation in my project. I put a warning so that the columns should not be empty. But there is no warning on the screen, where am I going wrong? TaskListValidator.cs, public class ...
Gökmen ADA's user avatar
2 votes
2 answers
99 views

Checking for Guid Whitespace in FluentValidation

public class GetCarQuery:IRequest<CartViewModel> { public Guid Id { get; set; } } public GetCarIdValidator() { RuleFor(x => x.Id) .NotNull() .NotEmpty() ...
Alaa Barakat's user avatar
0 votes
2 answers
40 views

fluentvalidation cascade stop fails to halt

I have the following : internal sealed class LabelValidator : AbstractValidator<string> { public LabelValidator() { RuleFor(label => label) .NotNull() ....
Vincent's user avatar
  • 510
0 votes
0 answers
32 views

How to conditionally require a related object property in ASP.NET Core 6?

I have related objects VehicleAcquisition and FleetValue. I want to make FleetValue.ConditionId required if VehicleAcquisition.RequestType.Label == "Replacement". The following solution ...
csharpdev's user avatar
0 votes
0 answers
52 views

Validate range between numbers with FluentValidation

I'm using FluentValidation to validate some fields, and there's one field I want to validate if it's between 2 numbers I set, but it's not working, using breakpoints it simply skips this step, looks ...
jvbs's user avatar
  • 417
0 votes
0 answers
17 views

Build dynamic fluent validator property selector

I'm generating dynamic validation rules for fluent validator. The framework takes the rule as a parameter: RuleFor(Expression<Func<T, TProperty>> expression) So basically a property ...
filur's user avatar
  • 2,206
0 votes
0 answers
65 views

Filter For Fluent Validation

I tried to create a filter for my fluent validations but I could not send the error messages to my page. I can not see the error messages when filter runs. Is there any way to do it? public class ...
Hasan's user avatar
  • 3
0 votes
2 answers
38 views

Is there any way to apply Fluent Validation for a group of similar properties in ViewModel?

I got a ViewModel (MovieNamesModel) as given below: { public string? MovieName1 { get; set; } public string? MovieName2 { get; set; } public string? MovieName3 { get; set; } ... ... public ...
Agnib's user avatar
  • 9
1 vote
1 answer
298 views

Not invoking FluentValidation in MediatR pipeline

I am using: MediatR 12.1.1 FluentValidation 11.6.0 I have created my validator: internal class CreateTemplateCommandValidator : AbstractValidator<CreateTemplateCommand> { public ...
defcon1's user avatar
  • 27
0 votes
0 answers
72 views

How do I code a generic validation API endpoint using fluent validation?

What I want to do is send my validator_dto and my model to the API endpoint and return true if it is suitable for my validation class, return false if it is not appropriate and give me a list of ...
nikki's user avatar
  • 25
0 votes
1 answer
142 views

Issues with FluentValidation implementation for .NET 7 Web API application

I have a .NET 7 web api with multiple controllers. Right now I am using repository pattern in the implementation. I wanted to implement generic validation pipeline similar to the one : https://code-...
santosh kumar patro's user avatar
1 vote
0 answers
29 views

FluentValidation with conditional validations and with different rules on the entity properties

I have an entity: public class BookDto { public string? Id { get; set; } public string? ExternalBookId { get; set; } public string? Name { get; set; } public string? Description { get; ...
hackp0int's user avatar
  • 4,084
0 votes
1 answer
56 views

FluentValidation Custom Validator with placeholders

say I've a class Customer like public string RegistrationNr public bool Archived I've created a validator internal sealed class AddCustomerValidator : AbstractValidator<AddCustomerViewModel> {...
Jeroen E's user avatar

1
2 3 4 5
29