-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
ServiceStack 4 Cookbook
By :
ServiceStack offers a number of ways to do validation of client requests. One of the easiest and the most powerful is the Fluent Validation syntax—we can use Language-Integrated Query (LINQ) to create expressions that describe the rules we want ServiceStack to follow when validating request DTOs. ServiceStack includes the type IRuleBuilder that has built-in things such as NotEmpty, NotEqual, LessThan, and so on, along with more advanced features, such as validating credit cards and e-mail addresses.
What we're going to do is add a validation for Greeting in order to show how validation works:
The first thing we're going to need to do is add the ValidationFeature plugin, as follows:
Plugins.Add(new ValidationFeature());
Next, we'll create a GreetingRequestValidator class that extends the AbstractValidator<T> class. In the constructor, we'll create rules for the Greeting objects that our service processes, as follows:
public...
Change the font size
Change margin width
Change background colour