Top Banner
Vertical Slices in .NET Bojan Veljanovski, CTO at HASELT 1
28

Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Apr 16, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Vertical Slices in .NETBojan Veljanovski, CTO at HASELT

1

Page 2: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

What is an user’s intent in software?

2

Page 3: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

User Intent - Reads and Writes

- WRITE is a request modeled as COMMAND triggered via HTTP POST

- READ is a request modeled as QUERY triggered via HTTP GET

- Commands modify data

- Queries retrieve data

3

Page 4: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

User Intent - CQRS

CQRS is a simple pattern, writing and reading data is placed in 2 separate classes which have single responsibility.

4

Page 5: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

DISCLAIMER

Nope… there is no silver bullet.5

Page 6: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

What we are going to talk about

- Overview

- Horizontal vs. Vertical user stories

- Horizontal vs. Vertical slices

- Commands & Queries

- Feature folders

- DEMO code

- Summary

6

Page 7: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

“Two“ starting points to build a system

- Horizontal first

- Vertical first

7

Page 8: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal vs. Vertical user stories

- Horizontal- Story 1: Create the new DB Table for Users

- Story 2: Create the DAL to access the DB Users

- Story 3: Create the Users business layer code that references the DAL

- Story 4: Write the Users UI screen

- Vertical- Story 1: User can register and provide username and

password.

- Story 2: User can manage multiple addresses.

- Story 3: User can add additional contact fields (phone, email, etc).

- Story 4: User can subscribe to a subscription plan.

- Story 5: Admin can manage subscription plans and pricing.

8

Page 9: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal vs. Vertical user stories

- Horizontal- Implement the database layer for A, B and C- Implement the business logic layer for A, B

and C- Implement the user interface for A, B and C

- Vertical- Implement A from end to end- Implement B from end to end- Implement C from end to end

9

Page 10: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal slicing is not natural in agile

- Changes usually happen vertically - You limit your application to the same horizontal

constraints for all features (regardless of the size and complexity)

- ...and more

10

Page 11: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

“Slicing” is a team organization thing too!

11

Page 12: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Vertical Slices over Horizontal Slices

- Horizontal slices is organization by technical layers.

- Vertical slices is organization by features (business requirements).

12

Page 13: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Vertical Slicing: The Stakeholder

Stakeholders talk and eat the cake in vertical slices. They want one delicious piece at a time, not only the vanila part.

Why don't we structure our code vertically as well?

13

Page 14: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal Slices

14

Page 15: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal Slices (2)

15

Page 16: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Horizontal Slices (3)

16

Page 17: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Vertical Slices

17

Page 18: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Organization structure

18

Page 19: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

19

Page 20: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

20

Page 21: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Addressing cross-cutting concerns

- Loggers- Validators- Transactions

21

Page 22: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

ASP.NET MVC - Feature Folders ViewEngine

22

Page 23: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

ASP.NET MVC - Feature Folders ViewEngine

23

Page 24: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Slide intentionally blank...

24

Page 25: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Can it easily evolve to CQRS?

25

Page 26: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

Can it easily evolve to SOA/Microservices?

26

Page 27: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

SUMMARY: Characteristics of good Vertical Slices- Code is structured primarily by feature,

secondary by layer- Have single responsibility (business-oriented)- Encapsulated and decoupled from other slices

- Complexity and defects are isolated in each slice, instead of each layer

- Increases developer’s understanding of each feature as a whole

- Enables incremental releases of features- Enables faster feedback loop- Enables support for potential simpler scaling out

- By Read/Write mechanics (CQRS), or- By Feature as a whole (SOA)

27

Page 28: Vertical Slices in .NET - Bojan Veljanovski, March 2016, MK.NET UG

SUMMARY: Trade-offs and Challenges

- Complete mindset shift

- Developers must be all-round-shaped (back, front, middle, db, all)

- Now you have twice as many classes as before

28