- read

Goodbye Controllers: Building Better Blazor Web Apps with Vertical Slices

Rico Fritzsche 25

Goodbye Controllers: Building Better Blazor Web Apps with Vertical Slices

Streamline Your .NET 8 Projects with the Power of MediatR and Blazor

Rico Fritzsche
Level Up Coding
Published in
10 min read2 days ago

--

Image licensed under the Unsplash+ License.

In this article, I want to revisit how the Vertical Slice Architecture can be used. This article takes an in-depth look at feature slicing and its application to server-side rendered (SSR) .NET 8 Blazor pages without the need for a controller class. You’ll find clear explanations and practical advice on several key points:

  1. An understanding of what Vertical Slice Architecture is and how it works within the .NET ecosystem using the power of the MediatR library.
  2. Insight into the distinctions between vertical slices and microservices, and when each is appropriate.
  3. The reasons why the traditional controller-based model may not be necessary in modern web app design.
  4. A practical, hands-on walkthrough for crafting a Razor page that leverages the vertical slice approach, offering a concise and independent feature slice for better maintainability and scalability.

By the end of this article, you should have a thorough understanding of vertical slice architecture and be well equipped to use it in your .NET 8 Blazor projects to increase their robustness and modularity.

What is Vertical Slice Architecture?

First, I want to clarify what exactly Vertical Slice Architecture means and why it is a good way to build your application. There are many patterns, but most of them sooner or later lead to a codebase with many dependencies. Good developers should always strive to improve their code and create something sustainable. I like to say that good code should not be complex, but easy to read and understand.

Let’s talk about why breaking a software system into small pieces is such a good approach. Well, I think the big advantage is that you focus on interactions rather than layers or technical affiliations. What I mean by that: Thinking in slices means focusing on exactly one input-output pair, i.e. one interaction. And every system is made up of interactions. Each slice must ensure that it receives the input from the user (or another system) and delivers the output.