Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vertical Slice Architecture - Are slices better...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for .NET Day .NET Day
August 27, 2026

Vertical Slice Architecture - Are slices better than layers?

Avatar for .NET Day

.NET Day

August 27, 2026

More Decks by .NET Day

Other Decks in Technology

Transcript

  1. 26.08.2026 Vertical Slice Architecture .NET Day Switzerland 2026 | Rolf

    Würth 1 It’s about layers and slices… 2 26.08.2026 WE KNOW HOW. 2 1
  2. 26.08.2026 About me… • Rolf Würth • Expert Software Engineer

    / Architect • Noser Engineering AG • .NET / Web / Cloud / GIS 3 26.08.2026 WE KNOW HOW. 3 Two common types of architecture UI Presentation App Services Domain Services Business Logic Dependencies Domain Data Access Database 4 Database 26.08.2026 WE KNOW HOW. 4 2
  3. 26.08.2026 Layered vs Domain-centric Architectures Both organize the code around

    architectural layers and technical responsibilities. Presentation Presentation Application Business Logic Domain Data Access Database 5 Persistence Infrastructure Database OS 26.08.2026 WE KNOW HOW. 5 Controller Controller Controller Presentation Controller Controller Controller Service Service Service Business Logic Service Service Service Repository Repository DBContext Data Access DBContext Repository Repository Database 6 26.08.2026 WE KNOW HOW. 6 3
  4. 26.08.2026 Controller Controller Controller Presentation Controller Controller Controller Service Service

    Service Business Logic Service Service Service Repository Repository DBContext Data Access DBContext Repository Repository Database 7 26.08.2026 WE KNOW HOW. 7 Challenges with Layered Architectures • Features are scattered across layers • High impact of change • Complexity accumulates across layers → Harder to understand → Harder to change → Harder to maintain 8 26.08.2026 WE KNOW HOW. 8 4
  5. 26.08.2026 Vertical Slice Architecture Source: https://www.jimmybogard.com/vertical-slice-architecture/ 9 Jimmy Bogard 26.08.2026

    WE KNOW HOW. 9 Vertical Slice Architecture “Instead of coupling across a layer, we couple vertically along a slice. Minimize coupling between slices, and maximize coupling in a slice.” 10 26.08.2026 WE KNOW HOW. 10 5
  6. 26.08.2026 What is a Vertical Slice? CreateActivity • One use

    case (or feature) implemented end-to-end Endpoint • Own input and output • Implementation organized around the use case • Minimal coupling to other slices 11 Handler Data Access 26.08.2026 WE KNOW HOW. 11 Create Activity' Implementation as a Vertical Slice in a Single File 12 26.08.2026 WE KNOW HOW. 12 6
  7. 26.08.2026 Code Structure Vertical Slices Layered ActivityTracker Controllers Activities ActivityController.cs

    CreateActivity KudosController.cs CreateActivityEndpoint.cs Services CreateActivityHandler.cs ActivityService.cs UpdateActivity KudosService.cs UpdateActivityEndpoint.cs Repositories UpdateActivityHandler.cs ActiviyRepository.cs KudosRepository.cs Kudos GiveKudos 13 26.08.2026 WE KNOW HOW. 13 14 Feature 8 Feature 7 Feature 6 Feature 5 Feature 4 Feature 3 Feature 2 Feature 1 Benefits: Evolvability and Isolation 26.08.2026 WE KNOW HOW. 14 7
  8. 26.08.2026 Benefits: Modularization 15 Feature 8 Feature 7 Feature 6

    Module B Feature 5 Feature 4 Feature 3 Feature 2 Feature 1 Feature 8 Feature 7 Feature 6 Feature 5 Feature 4 Feature 3 Feature 2 Feature 1 Module A 26.08.2026 WE KNOW HOW. 15 Benefits: Implementation Diversity Message HTTP API HTTP API App Infra Data Data App Database Domain Data 16 26.08.2026 WE KNOW HOW. 16 8
  9. 26.08.2026 Diversity 17 26.08.2026 WE KNOW HOW. 17 Features are

    isolated – but how can we share code? F1 18 F2 F3 26.08.2026 WE KNOW HOW. 18 9
  10. 26.08.2026 19 Architecture test to ensure feature independence using ArchUnitNET

    (https://github.com/TNG/ArchUnitNET) 26.08.2026 WE KNOW HOW. 19 4 Ways of Code Sharing AuthN / AuthZ Validation Logging F1 F2 F3 F1 F2 F3 F1 F2 F3 F1 F2 F3 Shared Domain Database 20 26.08.2026 WE KNOW HOW. 20 10
  11. 26.08.2026 Principles for Code Sharing • Share on demand →

    Avoid premature sharing. Start locally and extract common code when reuse actually emerges. • Keep related code together → Preserve the cohesion of the vertical slice • Preserve vertical boundaries → Don't unnecessarily couple independent features 21 26.08.2026 WE KNOW HOW. 21 Feature-Specific Sharing F1 22 F2 F3 F4 F5 26.08.2026 WE KNOW HOW. 22 11
  12. 26.08.2026 Feature-Specific Sharing ActivityTracker Activities CreateActivity UpdateActivity F1 F2 F3

    F4 PublishActivity F5 DeleteActivity Shared Kudos GiveKudos shared GetKudos Shared 23 26.08.2026 WE KNOW HOW. 23 Shared Domain Model F1 F2 F3 F4 F5 F6 F7 Domain Database 24 26.08.2026 WE KNOW HOW. 24 12
  13. 26.08.2026 Encapsulation of domain logic in an entity (Example) 25

    26.08.2026 WE KNOW HOW. 25 Semi-vertical Slices 26 26.08.2026 WE KNOW HOW. 26 13
  14. 26.08.2026 Bounded Access Features F1 F3 F2 IRepository1 F5 IRepository2

    Domain Domain 27 F4 26.08.2026 WE KNOW HOW. 27 Cross-cutting Concerns Logging Transactions Validation F1 28 F2 F3 F4 F5 26.08.2026 WE KNOW HOW. 28 14
  15. 26.08.2026 Implementation Options Mechanism Typical Scope ASP.NET Core Middleware HTTP

    request pipeline Mediator* / Pipeline Behavior Handlers (Filtered by generic type constraints / markers) Handlers (Filtered by generic type constraints / markers) Whatever scope you need Decorators (Scrutor / DI) Custom solution *) Multiple Mediator-Libraries available 29 26.08.2026 WE KNOW HOW. 29 Applying Filter Constraints GET POST Web API 30 IQuery<T> Query Command ICommand<T> IQueryHandler <TQuery, TRespone> Query Handler Command Handler ICommandHandler <TCommand, TRespone> 26.08.2026 WE KNOW HOW. 30 15
  16. 26.08.2026 Cross-cutting Concerns with Mediator Vertical Slice Endpoint DI Container

    Mediator Framework Pipeline Behavior Pre Resolve Dependency next() Handler Authorization Behavior IPipelineBehavior <TRequest, TResponse> Transaction Behavior IPipelineBehavior<TCom mand, TResponse> Post Data Access 31 26.08.2026 WE KNOW HOW. 31 Cross-cutting Concerns with Mediator Vertical Slice Endpoint DI Container Mediator Framework Authorization Behavior IPipelineBehavior <TRequest, TResponse> Pipeline Behavior Pre Validator next() Handler Post Resolve Dependency Validation Behavior (Generic Wrapper) Transaction Behavior IPipelineBehavior<TCom mand, TResponse> Data Access Register Dependency 32 26.08.2026 WE KNOW HOW. 32 16
  17. 26.08.2026 33 26.08.2026 WE KNOW HOW. 34 26.08.2026 WE KNOW

    HOW. CreateActivity implementation with a mediator library (Example). Library: https://github.com/martinothamar/Mediator 33 34 17
  18. 26.08.2026 Cross-cutting Concerns with Decorators Vertical Slice DI Container Endpoint

    AuthorizationDecorator IHandler<T> TransactionDecorator Resolve Dependency (Constructor Injection) ValidationDecorator Handler Handler ValidationDecorator (Generic Wrapper) Runtime: Resolve & Execute Data Access TransactionDecorator ICommandHandler<T> Validator Register Dependency 35 26.08.2026 WE KNOW HOW. 35 CreateActivity implementation with the decorator pattern (Example). 36 26.08.2026 WE KNOW HOW. 36 18
  19. 26.08.2026 37 26.08.2026 WE KNOW HOW. Top: ActivityValidator using FluentValidation

    (https://docs.fluentvalidation.net/en/latest/) Bottom: ValidationDecorator example with injected feature-specific validator. 37 Decorator registration with Scrutor (https://github.com/khellang/Scrutor) 38 26.08.2026 WE KNOW HOW. 38 19
  20. 26.08.2026 Putting it all together… Infrastructure . Cross-cutting Concerns shared

    shared shared shared Domain A Domain B Database Database 39 26.08.2026 WE KNOW HOW. 40 26.08.2026 WE KNOW HOW. shared 39 40 20
  21. 26.08.2026 Challenges • Changing the mindset Unlearn patterns acquired from

    layered architectures • Managing duplication & sharing Finding the right balance between independence and reuse • Maintaining consistency Balancing slice-specific solutions with team-wide conventions 41 26.08.2026 WE KNOW HOW. 41 Key Takeaways • Organize by feature, not by layer • Prefer independence over premature sharing • Use appropriate code-sharing strategies 42 26.08.2026 WE KNOW HOW. 42 21
  22. 26.08.2026 Happy Coding with Vertical Slice Architecture! 43 26.08.2026 WE

    KNOW HOW. 43 Any questions? 44 26.08.2026 WE KNOW HOW. 44 22