Is it possible to combine [FromRoute] and [FromBody] in ASP.NET Core?

It’s doable by a custom model binder as mentioned in the comment. Here is a few code snippets to wire everything up, with the example you can send a http request with the following JSON body to an API /api/cats?From=james&Days=20 { “Name”:””, “EyeColor”:”Red” } A few classes, you can find them here as well: https://github.com/atwayne/so-51316269 … Read more

How can I access the collection item being validated when using RuleForEach?

Currently there are no functionality in FluentValidation, that allows to set validation state the way you want. RuleForEach was designed to prevent creation of trivial validators for simple collection items, and it’s implementation didn’t cover all possible use cases. You can create separate validator class for Order and apply it using SetCollectionValidator method. To access … Read more

FluentValidation unique name validation using database

Predicate Validator (aka Must) has an overload, which accepts predicate with two parameters (validated object and property value). In your case predicate will have type Func<Category, string, bool>. So just add Category parameter to your unique name validation method: private bool UniqueName(Category category, string name) { ProjecteDataContext _db = new ProjecteDataContext(); var dbCategory = _db.Categories … Read more

FluentValidation – validating across multiple properties

Finally got it working after I re-read the documentation: “Note that there is an additional overload for Must that also accepts an instance of the parent object being validated.” public class EventModelValidator : AbstractValidator<EventViewModel> { public EventModelValidator() { RuleFor(x => x.StartDate) .NotEmpty().WithMessage(“Date is required!”) .Must(BeAValidDate).WithMessage(“Invalid date”); RuleFor(x => x.StartTime) .NotEmpty().WithMessage(“Start time is required!”) .Must(BeAValidTime).WithMessage(“Invalid Start … Read more

Stop Fluent Validation on first failure

Just check for null before running the rules that depend on them, using a When condition. this.CascadeMode = CascadeMode.StopOnFirstFailure; RuleFor(x => x.TechnicalHeader).NotNull().WithMessage(“Header cannot be null”); // Ensure TechnicalHeader is provided When(x => x.TechnicalHeader != null, () => { RuleFor(x => x.TechnicalHeader.Userid).NotEmpty().WithMessage(“Userid cannot be null or an empty string”); RuleFor(x => x.TechnicalHeader.CabCode).GreaterThan(0).WithMessage(“CabCode cannot be or less … Read more

Add validation to a MediatR behavior pipeline?

The process is exactly the same, you just have to change the interface to use the new IPipelineBehavior<TRequest, TResponse> interface. public class ValidationBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : IRequest<TResponse> { private readonly IEnumerable<IValidator<TRequest>> _validators; public ValidationBehavior(IEnumerable<IValidator<TRequest>> validators) { _validators = validators; } public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next) { var context = new … Read more

techhipbettruvabetnorabahisbahis forumueduedusedusedusedusedusedusedueduedus