I have to overlook something around getting fluent validation to run in the main Service-Stack application that I created. I follow the example here . For the life of me I can’t get my validators to shoot ???? Breadcrumbs, there must be something stupid that I'm missing .... ???
I issue a user request against User-Service ( http: //my.service/users ), the request goes directly without calling the corresponding validator registered.
Request: {"Name": "," Company ":" Co. "," Age ": 10," Account ": 110," Address ":" 123 brown street ".}
Answer: "user saved ..."
Here is the code:
1.DTO
[Route("/users")]
public class User
{
public string Name { get; set; }
public string Company { get; set; }
public int Age { get; set; }
public int Count { get; set; }
public string Address { get; set; }
}
2.Validator
public class UserValidator : AbstractValidator<User>
{
public UserValidator()
{
RuleFor(r => r.Name).NotEmpty();
RuleFor(r => r.Age).GreaterThan(0);
}
}
3.AppHostBase
public class ValidationAppHost : AppHostBase
{
public ValidationAppHost()
: base("Validation Test", typeof(UserService).Assembly)
{
}
public override void Configure(Funq.Container container)
{
Plugins.Add(new ValidationFeature());
container.RegisterValidators(typeof(UserValidator).Assembly);
}
}
4.Service
public class UserService : Service
{
public object Any(User user)
{
return "user saved...";
}
}
5.Global.asax.cs
protected void Application_Start(object sender, EventArgs e)
{
new ValidationAppHost().Init();
}
source
share