ServiceStack and FluentValidation DO NOT fire

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());

        //This method scans the assembly for validators
        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();
    }
+5
source share
1 answer

Well .... found the problem .... I (by mistake) installed (via nuget) and referenced in my project FluentValidation.dll with the FluentValidation Service-Stack implementation (see namespace ServiceStack.FluentValidation). As soon as I removed this single invalid FluentValidation link and made sure that my validator was extended from the service stack implementation, the AbstractValidatorvalidators were correctly processed ...

+6
source

All Articles