'Compare Fluent Validation Model with another model
I need to get a Model inside validator to compare data,
public class AttachFile
{
public int PersonId {get;set;}
public string Name {get;set;}
}
public class AttachFileValidator : AbstractValidator<AttachFile>
{
private PersonDetails _personDetails;
private IExamService _examService;
public AttachFileValidator(IExamService examService)
{
_examService = examService;
_personDetails = await _examService.GetPesronDetailsResultAsync(**AttachFile.PersonId**, "01", "02");
RuleFor(x => x.Name).Equal(_personDetails.Name)
.WithMessage("Name value is not same original name value");
}
}
I try to get person details from exam service to ensure that the name of person in the model attach file is the same of name from exam service, but the problem is I can not pass person id as AttachFile.PersonId, and the way of calling validator is by pipeline as
public static class DependencyInjection
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
return services;
}
}
so if any way to pass AttachFile.PersonId, please help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
