I have a validator, and I'm trying to use some session variables as part of the validation logic, however base.Request always returns as NULL. I added it to the lambda function as instructed, and the documentation for checking seems to be out of date, as the tip in the Free checking for dtos request mentions use IRequiresHttpRequest, but the AbstractValidator class already implements IRequiresRequest.
This is my code:
public class UpdateContact : IReturn<UpdateContactResponse>
{
public Guid Id { get; set; }
public string Reference { get; set; }
public string Notes { get; set; }
public List<Accounts> Accounts { get; set; }
}
public class UpdateContactResponse : ResponseBase
{
public Guid ContactId { get; set; }
}
public class UpdateContactValidator : AbstractValidator<UpdateContact>
{
public UpdateContactValidator(IValidator<AccountDetail> accountDetailValidator)
{
RuleSet(ApplyTo.Post | ApplyTo.Put, () => {
var session = base.Request.GetSession() as CustomAuthSession;
RuleFor(c => c.Reference).Must(x => !string.IsNullOrEmpty(x) && session.Region.GetCountry() == RegionCodes.AU);
});
RuleFor(R => R.Accounts).SetCollectionValidator(accountDetailValidator);
}
}
Is there something I am missing?
source
share