Before you begin: Join our book community on Discord
Give your feedback straight to the author himself and chat to other early readers on our Discord server (find the “architecting-aspnet-core-apps-3e” channel under EARLY ACCESS SUBSCRIPTION).
https://packt.link/EarlyAccess
This chapter introduces Vertical Slice Architecture, an effective way to organize our ASP.NET Core applications. Vertical Slice Architecture moves elements from multiple layers to a feature-oriented design, helping us maintain a clean, simple, cohesive, loosely-coupled, and manageable codebase.Vertical Slice Architecture flips our architectural perspective toward simplified architecture. Historically, we divided the logic of a feature across various layers like UI, business logic, and data access. However, we create independent slices of functionality with Vertical Slice Architecture instead. Think of your application as a cake; instead of cutting it horizontally (layers), we’re cutting vertically (features), with each slice being fully functional on its own.This style changes how we design and organize our project, testing strategies, and coding approach. We don’t have to worry about bloated controllers or overly complicated “God objects”; instead, making changes becomes more manageable because of the loose coupling between features.This chapter guides you through applying Vertical Slice Architecture to your ASP.NET Core applications, detailing how to handle commands, queries, validation, and entity mapping using CQS, MVC, MediatR, AutoMapper, and FluentValidation, which we explored in the previous chapters.
We don’t have to use those tools to apply the architectural style and can replace those libraries with others or even code the whole stack ourselves.
By the end of this chapter, you will understand Vertical Slice Architecture and its benefits, and should have the confidence to apply this style to your next project. In this chapter, we cover the following topics:
- Anti-pattern – Big Ball of Mud
- Vertical Slice Architecture
- Continuing your journey: A few tips and tricks
Let’s journey through the vertical slices and piece the architecture together, one slice at a time.
Anti-pattern – Big Ball of Mud
Let’s start with an anti-pattern. The Big Ball of Mud anti-pattern describes a system that ended badly or was never properly designed. Sometimes a system starts great but evolves into a Big Ball of Mud due to pressure, volatile requirements, impossible deadlines, bad practices, or other reasons. We often refer to the Big Ball of Mud as spaghetti code, which means the same thing.This anti-pattern means a very hard-to-maintain codebase, poorly written code that is difficult to read, lots of unwanted tight coupling, low cohesion, or worse: all that in the same codebase.Applying the techniques covered in this book should help you avoid this anti-pattern. Aim at small, well-designed components that are testable. Enforce that using automated testing. Refactor and improve your codebase whenever you can, iteratively (continuous improvement). Apply the SOLID principles. Define your application pattern before starting. Think of the best way to implement each component and feature; do research, and make one or more proof of concept or experiments if unsure of the best approach. Ensure you understand the business requirements of the program you are building (this is probably the best advice). Those tips should help you avoid creating a Big Ball of Mud.Building feature-oriented applications is one of the best ways to avoid creating a Big Ball of Mud. Let’s get started!
Leave a Reply