Periodic Validation Issues Using ServiceSttack

I am using ServiceStack to create an API and at the same time, I am using a plugin that allows Razor views to return html to browsers.

I have the correct setup and setup. I know this because I am getting validation messages on the corresponding Razor view and the messages are accurate. However, if I change the Razor view at all (and "in general", I mean something as simple as adding a line break and then immediately removing it), I get a 500 error followed by a page space.

In other cases, while simply refreshing the page to view the Razor view style, the validation simply returns an empty page with the same invalid 500 error. And of course, if I remove the validation, the Razor view is rendered only 100% of the time.

What should I do for validation to work at all times? My code is straight forward and matches everything I could read in the Docs. Namely, both the response and the requests are in the same namespace and the validator is encoded into the request.

Here is the DTO request

namespace MyServer.DTO
{
    [Validator(typeof(SignUpValidator))]
    [Route("SignUp")]
    public class SignUp : IReturn<SignUpResponse>
    {
        public string UserName { get; set; }
        public string Email { get; set; }
        public string EmailConfirm { get; set; }
        public string Password { get; set; }
        public string PasswordConfirm { get; set; }
        public int UserId { get; set; }
    }
}

      

Here is the relevant validator

namespace MyServer.DTO
{
    public class SignUpValidator : AbstractValidator<SignUp>
    {
        public SignUpValidator()
        {
            RuleSet(ApplyTo.Post, () =>
                {
                    RuleFor(e => e.UserName).NotEmpty();
                    RuleFor(e => e.Email).NotEmpty();
                    RuleFor(e => e.EmailConfirm).NotEmpty();
                    RuleFor(e => e.Password).NotEmpty();
                    RuleFor(e => e.PasswordConfirm).NotEmpty();
                }
            );
        }
    }
}

      

Here's the answer

namespace MyServer.DTO
{
    public class SignUpResponse
    {
        bool DidSucceed { get; set; }
        int NewUserId { get; set; }
        public ResponseStatus ResponseStatus { get; set; }
    }
}

      

And finally, here is the code that sets up the validation plugin

        Plugins.Add(new ValidationFeature());
        Container.RegisterValidators(typeof(SignUpService).Assembly);

      

As you can see, everything looks pretty vanilla and from the book, but for some reason this setup is very fragile. Any modification of the corresponding Razor look and I am getting the above errors. Then I have to recompile several times until it works again.

I should also note that if I use the REST console (google chrome thingy extension) to test this, I get the following results when posting to the same URI:

  • Content-Type is set to: application / json - everything works as intended. 400 Answer with errors indicated in the corpus of the answer.
  • Content-Type set to: application / html - Abort sequentially. 500 Answer without data in the corpus of the answer.

There must be something I'm missing.

Thanks a lot for your time and I would appreciate any help.

Thanks again.

+3


source to share





All Articles