Skip to content

Commit 8273cc5

Browse files
committed
Update design-message-based-apis.md
1 parent 0c642e8 commit 8273cc5

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

MyApp/_pages/design-message-based-apis.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,25 @@ public class BookingsService : Service
261261
## Error Handling and Validation
262262

263263
For info on how to add validation you either have the option to just [throw C# exceptions](/error-handling#throwing-c-exceptions)
264-
and apply your own customizations to them. You also have the option to use the built-in [Fluent Validation](/validation)
265-
but you don't need to inject them into your service as they can all be registered with a single line in your AppHost, e.g:
264+
and apply your own customizations to them, in addition you also have the option to use the built-in
265+
[Declarative Validator](/declarative-validation) attributes on your Request DTO:
266266

267267
```csharp
268-
container.RegisterValidators(typeof(CreateBookingValidator).Assembly);
268+
[ValidateIsAuthenticated]
269+
public class CreateBooking : IPost, IReturn<CreateBookingResponse>
270+
{
271+
[ValidateNotNull]
272+
public DateTime? StartDate { get; set; }
273+
274+
[ValidateGreatorThan(0)]
275+
public int ShiftId { get; set; }
276+
277+
[ValidateGreatorThan(0)]
278+
public int Limit { get; set; }
279+
}
269280
```
270281

271-
Validators are no-touch and invasive free meaning you can add them using a layered approach and maintain them without
272-
modifying the service implementation or DTO classes. Since they require an extra class We'd only use them on operations
273-
with side-effects e.g. **POST** or **PUT**, as **GET** requests tend to have minimal validation so throwing C# Exceptions
274-
typically requires less boilerplate. Here's an example of a validator you could have when creating a Booking:
282+
Or for more control you can use custom [Fluent Validation](/validation) validators. Validators are no-touch and invasive free meaning you can add them using a layered approach and maintain them without modifying the service implementation or DTO classes. Since they require an extra class We'd only use them on operations with side-effects e.g. **POST** or **PUT**, as **GET** requests tend to have minimal validation so throwing C# Exceptions typically requires less boilerplate. Here's an example of a validator you could have when creating a Booking:
275283

276284
```csharp
277285
public class CreateBookingValidator : AbstractValidator<CreateBooking>

0 commit comments

Comments
 (0)