Clean Architecture Jason Taylor Join the Conversation #GOTOCph - - PowerPoint PPT Presentation

clean architecture
SMART_READER_LITE
LIVE PREVIEW

Clean Architecture Jason Taylor Join the Conversation #GOTOCph - - PowerPoint PPT Presentation

Clean Architecture Jason Taylor Join the Conversation #GOTOCph @JasonGtAu Join the Conversation #GOTOCph @JasonGtAu Jason Taylor SSW Solution Architect Visiting from Australia .NET Developer Since 2002 Keep It Simple, Stupid! jasongtau


slide-1
SLIDE 1

Clean Architecture

Jason Taylor

Join the Conversation #GOTOCph @JasonGtAu

slide-2
SLIDE 2

Join the Conversation #GOTOCph @JasonGtAu

slide-3
SLIDE 3
slide-4
SLIDE 4

SSW Solution Architect

Jason Taylor

github.com/jasongt youtube.com/jasongt

Join the Conversation #DotNetCoreSuperpowers @SSW_TV

jasongtau codingflow.net

Visiting from Australia .NET Developer Since 2002 Keep It Simple, Stupid!

slide-5
SLIDE 5

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-6
SLIDE 6

Clean Architecture

Independent of frameworks Testable Independent of UI Independent of database Independent anything external

Join the Conversation #GOTOCph @JasonGtAu

Presenta sentation tion Infrastr struct cture Applica ication tion Domai main

slide-7
SLIDE 7

Northwind Traders Sample

Clean Architecture ASP.NET Core 3.0 Entity Framework Core 3.0 ASP.NET Core Identity 3.0 Repo bit.ly/northwind-traders

Join the Conversation #GOTOCph @JasonGtAu

slide-8
SLIDE 8

Clean Architecture Template

.NET Core Template Package ASP.NET Core 3.0 Entity Framework Core 3.0 ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln

Join the Conversation #GOTOCph @JasonGtAu

slide-9
SLIDE 9

Domain contains enterprise-wide logic and types Application contains business-logic and types Infrastructure contains all external concerns Presentation and Infrastructure depend only on Application Infrastructure and Presentation components can be replaced with minimal effort

Join the Conversation #GOTOCph @JasonGtAu

Key Points

slide-10
SLIDE 10

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-11
SLIDE 11

Overview

Entities Value Objects Enumerations Logic Exceptions

Join the Conversation #GOTOCph @JasonGtAu

Presenta sentation tion Applica ication tion Infrastr struct cture Domai main

slide-12
SLIDE 12

Demo

Reviewing the Domain layer

Join the Conversation #GOTOCph @JasonGtAu

slide-13
SLIDE 13

Avoid using data annotations Use value objects where appropriate Create custom domain exceptions Initialise all collections & use private setters Automatically track changes

Join the Conversation #GOTOCph @JasonGtAu

Key Points

slide-14
SLIDE 14

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-15
SLIDE 15

Overview

Interfaces Models Logic Commands / Queries Validators Exceptions

Join the Conversation #GOTOCph @JasonGtAu

Presenta sentation tion Applica ication tion Infrastr struct cture Domai main

slide-16
SLIDE 16

CQRS

Command Query Responsibility Segregation Separate reads (queries) from writes (commands) Can maximise performance, scalability, and simplicity Easy to add new features, just add a new query or command Easy to maintain, changes only affect one command or query

Join the Conversation #GOTOCph @JasonGtAu

slide-17
SLIDE 17

CQRS + MediatR = ♥

Define commands and queries as requests Application layer is just a series of request / response

  • bjects

Ability to attach additional behaviour before and / or after each request, e.g. logging, validation, caching, authorisation and so on

Join the Conversation #GOTOCph @JasonGtAu

slide-18
SLIDE 18

Demo

Reviewing the Application layer

Join the Conversation #GOTOCph @JasonGtAu

slide-19
SLIDE 19

Using CQRS + MediatR simplifies your overall design MediatR simplifies cross cutting concerns Fluent Validation is useful for all validation scenarios AutoMapper simplifies mapping and projections Independent of infrastructure concerns

Join the Conversation #GOTOCph @JasonGtAu

Key Points

slide-20
SLIDE 20

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-21
SLIDE 21

Overview

Persistence Identity File System System Clock API Clients

Join the Conversation #GOTOCph @JasonGtAu

Presenta sentation tion Applica ication tion Infrastr struct cture Domai main

slide-22
SLIDE 22

Unit of Work and Repository Patterns

Should we implement these patterns? It isn’t always the best choice, because:

EF Core insulates your code from database changes DbContext acts as a unit of work DbSet acts as a repository EF Core has features for unit testing without repositories

Join the Conversation #GOTOCph @JasonGtAu

slide-23
SLIDE 23

What do the experts think?

Join the Conversation #GOTOCph @JasonGtAu

I’m over Repositories, and definitely over abstracting your data layer. No, the repository/unit-of-work pattern isn’t useful with EF Core. No, you don’t need a repository. But there are many benefits and you should consider it!

slide-24
SLIDE 24

Demo

Reviewing the Infrastructure layer

Join the Conversation #GOTOCph @JasonGtAu

slide-25
SLIDE 25

Independent of the database Use Fluent API configuration over data annotations Prefer conventions over configuration Automatically apply all entity type configurations No layers depend on Infrastructure layer, e.g. Presentation layer

Join the Conversation #GOTOCph @JasonGtAu

Key Points

slide-26
SLIDE 26

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-27
SLIDE 27

Overview

SP SPA A – An Angular, ular, React act, , Vue ue Web AP API Razor Pages MVC Web Forms

Join the Conversation #GOTOCph @JasonGtAu

Presenta sentation tion Applica ication tion Infrastr struct cture Domai main

slide-28
SLIDE 28

Demo

Reviewing the Presentation layer

Join the Conversation #GOTOCph @JasonGtAu

slide-29
SLIDE 29

Controllers should not contain any application logic Create and consume well defined view models Open API bridges the gap between the front end and back end NSwag automates generation of Open API specification and clients

Join the Conversation #GOTOCph @JasonGtAu

Key Points

slide-30
SLIDE 30

Clean Architecture Infrastructure Layer Application Layer Presentation Layer Next Steps Domain Layer

Agenda

slide-31
SLIDE 31

Using the Solution Template

Join the Conversation #GOTOCph @JasonGtAu

C:\Code\CaTodo>dotnet new -i Clean.Architecture.Solution.Template C:\Code\CaTodo>dotnet new ca-sln The template "Clean Architecture Solution" was created successfully. C:\Code\CaTodo>

slide-32
SLIDE 32

Join the Conversation #GOTOCph @JasonGtAu

slide-33
SLIDE 33

Join the Conversation #GOTOCph @JasonGtAu

slide-34
SLIDE 34

Thank you!

info@ssw.com.au www.ssw.com.au

Sydney | Melbourne | Brisbane

@jasongtau

bit.ly/ca-sln bit.ly/northwind-traders