Book Image

An Atypical ASP.NET Core 5 Design Patterns Guide

By : Carl-Hugo Marcotte
Book Image

An Atypical ASP.NET Core 5 Design Patterns Guide

By: Carl-Hugo Marcotte

Overview of this book

Design patterns are a set of solutions to many of the common problems occurring in software development. Knowledge of these design patterns helps developers and professionals to craft software solutions of any scale. ASP.NET Core 5 Design Patterns starts by exploring basic design patterns, architectural principles, dependency injection, and other ASP.NET Core mechanisms. You’ll explore the component scale as you discover patterns oriented toward small chunks of the software, and then move to application-scale patterns and techniques to understand higher-level patterns and how to structure the application as a whole. The book covers a range of significant GoF (Gangs of Four) design patterns such as strategy, singleton, decorator, facade, and composite. The chapters are organized based on scale and topics, allowing you to start small and build on a strong base, the same way that you would develop a program. With the help of use cases, the book will show you how to combine design patterns to display alternate usage and help you feel comfortable working with a variety of design patterns. Finally, you’ll advance to the client side to connect the dots and make ASP.NET Core a viable full-stack alternative. By the end of the book, you’ll be able to mix and match design patterns and have learned how to think about architecture and how it works.
Table of Contents (27 chapters)
1
Section 1: Principles and Methodologies
5
Section 2: Designing for ASP.NET Core
11
Section 3: Designing at Component Scale
15
Section 4: Designing at Application Scale
21
Section 5: Designing the Client Side
25
Acronyms Lexicon

What this book covers

Section 1, Principles and Methodologies

This section contains the book's foundations: an overview of unit testing and xUnit, the SOLID principles, and some theory and examples on how to design software.

Chapter 1, Introduction to .NET, contains the prerequisites and an explanation of how the book works as well as a few important topics that will be useful to a software developer.

Chapter 2, Testing Your ASP.NET Core Application, introduces you to the basics of unit testing and the xUnit testing framework as well as to some good practices and methodologies to help write unit tests.

Chapter 3, Architectural Principles, lays the architectural ground with crucial principles used throughout the book and extremely important to any engineer trying to write "SOLID code."

Section 2, Designing for ASP.NET Core

This section introduces ASP.NET Core-specific subjects, including Model-View-Controller (MVC), View Models, DTOs, and a few classic design patterns. We also deep dive into dependency injection and explore the evolved usage of certain patterns in ASP.NET Core as pillars of modern software engineering.

Chapter 4, The MVC Pattern using Razor, introduces you to the Model-View-Controller and the View Model design patterns to render views using Razor and ASP.NET Core MVC.

Chapter 5, The MVC Pattern for Web APIs, takes you further on the ASP.NET Core MVC journey, focusing on web APIs. We explore the Data Transfer Object (DTO) pattern and API contracts.

Chapter 6, Understanding the Strategy, Abstract Factory, and Singleton Design Patterns, introduces you to the traditional implementation of three basic Gang of Four (GoF) design patterns: Strategy, Abstract Factory, and Singleton.

Chapter 7, Deep Dive into Dependency Injection, takes the ASP.NET Core dependency injection container for a ride, introducing you to one of the most important aspects of modern software development. This chapter connects ASP.NET Core and the SOLID principles. Once the basics of dependency injection are laid out, we review the previous three GoF design patterns and revisit them using dependency injection, opening the way to build testable, flexible, and reliable software.

Chapter 8, Options and Logging Patterns, takes ASP.NET Core-related subjects and digs into them. We cover different options patterns and the abstraction provided to us. We also explore how to leverage logging in .NET 5.

Section 3, Designing at Component Scale

This section focuses on component design, where we study how an individual piece of software can be crafted to achieve a particular goal. We explore a few more GoF patterns that should help us design SOLID data structures and components as well as simplifying the complexity of our code by encapsulating our logic in smaller units.

Chapter 9, Structural Patterns, introduces you to four new GoF structural design patterns and a few variants, such as transparent façades and opaque façades. It also introduces you to Scrutor, an open source project that adds support for the dependency injection of decorators.

Chapter 10, Behavioral Patterns, introduces two GoF behavioral design patterns and concludes by mixing them together as a final improvement on the code sample's design.

Chapter 11, Understanding the Operation Result Design Pattern, covers multiple variants of the Operation Result design pattern, structuring a result object to carry more than a simple result.

Section 4, Designing at Application Scale

This section takes a step forward, leading toward application design and introducing layering, vertical slices, and microservices. We overview each technique making sure you know how to get started. We also cover different component-level patterns that help put those architectural styles together.

Chapter 12, Understanding Layering, introduces you to layering and clean architecture, covering the primary objectives behind the presentation, domain, data (persistence) layers, and their clean architecture counterparts, which is the apogee of layering. It also highlights the evolution of application design that happened in the last few decades, helping you to understand where it started (the beginning of the chapter) and where it is headed (the end of the chapter).

Chapter 13, Getting Started with Object Mappers, covers object mapping (that is, copying an object into another), also known as the Translator pattern, the Mapper pattern, and Entity Translator. The chapter introduces AutoMapper at the end, an open source library, to help us cover the most common scenarios automatically.

Chapter 14, Mediator and CQRS Design Patterns, introduces the Command Query Responsibility Segregation (CQRS) and the Mediator patterns. After covering those two patterns, we explore an open source tool named MediatR that is foundational to many subsequent subjects.

Chapter 15, Getting Started with Vertical Slice Architecture, introduces Vertical Slice Architecture. It uses a number of the previous patterns and tools that we have explored to piece together a different way to see the design of an application. It also introduces FluentValidation, which gets added to MediatR and AutoMapper.

Chapter 16, Introduction to Microservices Architecture, introduces microservices, what they are, what they are not, and talks about a few related patterns. It is a theoretical chapter introducing many concepts, such as message queues, events, Publish-Subscribe, and Gateway patterns. We also revisit CQRS at cloud scale. At the end of the chapter, we explore the basics of containers.

Section 5, Designing the Client Side

This section introduces multiple UI patterns that we can use when developing ASP.NET Core 5 applications, such as Blazor, Razor Pages, and various types of components. It overviews what ASP.NET Core 5 offers in terms of user interfaces, leading to additional learning paths if you are interested.

Chapter 17, ASP.NET Core User Interfaces, explores most of the UI elements available to us in ASP.NET Core 5, such as Razor Pages, Partial Views, Tag Helpers, View Components, Display Templates, and Editor Templates. We also explore multiple C# 9 features, such as init-only properties and record classes.

Chapter 18, A Brief Look into Blazor, touches upon Blazor Server quickly, then explores Blazor WebAssembly (Wasm) to complete our journey and transform C#/.NET into a full-stack alternative to other JavaScript technologies. We explore Razor Components and the Model-View-Update design pattern. We end the chapter with a medley of possibilities you can start digging into.