ServiceStack (新しい API を使用) を使用して、DTO を検証しようとしています。検証をシミュレートするための簡単なコードを作成しましたが、明らかに起動していないか、少なくとも期待どおりに応答にエラーが表示されていません。私のコードは次のとおりです。
DTO:
[Route("/users/login")]
public class UserLogin
{
public string Email { get; set; }
public string Password { get; set; }
}
バリデータ自体:
public class UserLoginValidator : AbstractValidator<UserLogin>
{
public UserLoginValidator()
{
RuleSet(ApplyTo.Get, () =>
{
RuleFor(x => x.Email).NotEmpty().WithMessage("Please enter your e-mail.");
RuleFor(x => x.Email).EmailAddress().WithMessage("Invalid e-mail.");
RuleFor(x => x.Password).NotEmpty().WithMessage("Please enter your password.");
});
}
}
ホストでの検証の構成:
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(UserLoginValidator).Assembly);
そしてサービス:
public class LoginService : Service
{
public object Get(UserLogin request)
{
var response = new { SessionId = Guid.NewGuid() };
return response;
}
}
それを機能させるために行う必要がある他の構成または調整はありますか?
ありがとう!