Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Architecting ASP.NET Core Applications - Third Edition

You're reading from  Architecting ASP.NET Core Applications - Third Edition

Product type Book
Published in Mar 2024
Publisher Packt
ISBN-13 9781805123385
Pages 806 pages
Edition 3rd Edition
Languages
Author (1):
Carl-Hugo Marcotte Carl-Hugo Marcotte
Profile icon Carl-Hugo Marcotte
Toc

Table of Contents (27) Chapters close

Preface 1. Section 1: Principles and Methodologies
2. Introduction 3. Automated Testing 4. Architectural Principles 5. REST APIs 6. Section 2: Designing with ASP.NET Core
7. Minimal APIs 8. Model-View-Controller 9. Strategy, Abstract Factory, and Singleton Design Patterns 10. Dependency Injection 11. Application Configuration and the Options Pattern 12. Logging Patterns 13. Section 3: Component Patterns
14. Structural Patterns 15. Behavioral Patterns 16. Operation Result Pattern 17. Section 4: Application Patterns 18. Layering and Clean Architecture 19. Object Mappers 20. Mediator and CQS Patterns 21. Getting Started with Vertical Slice Architecture 22. Request-EndPoint-Response (REPR) 23. Introduction to Microservices Architecture 24. Modular Monolith 25. Other Books You May Enjoy
26. Index

Using the ValidateOptionsResultBuilder class

ValidateOptionsResultBuilder is a new type in .NET 8. It allows us to dynamically accumulate validation errors and create a ValidateOptionsResult object representing its current state.

The name of the project in the source code is ValidateOptionsResultBuilder.

Its basic usage is straightforward, as we are about to see.

In this project, we are validating the MyOptions object. The type has multiple validation rules, and we want to ensure we are not stopping after the first rule fails validation so a consumer would know all the errors in one go. To achieve this, we decided to use the ValidateOptionsResultBuilder class.

Let’s start with the options class:

namespace ValidateOptionsResultBuilder;
public class MyOptions
{
    public string? Prop1 { get; set; }
    public string? Prop2 { get; set; }
}

Next, let’s implement a validator class that enforces that both properties can’t be empty...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime