clean architecture - goto conference · 2019-11-22 · asp.net core identity 3.0 repo bit.ly/ca-sln...
TRANSCRIPT
![Page 1: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/1.jpg)
Clean ArchitectureJason Taylor
Join the Conversation #GOTOCph @JasonGtAu
![Page 2: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/2.jpg)
Join the Conversation #GOTOCph @JasonGtAu
![Page 3: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/3.jpg)
![Page 4: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/4.jpg)
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!
![Page 5: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/5.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 6: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/6.jpg)
Clean Architecture
Independent of frameworks
Testable
Independent of UI
Independent of database
Independent anything external
Join the Conversation #GOTOCph @JasonGtAu
Presentation
Infrastructure
Application
Domain
![Page 7: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/7.jpg)
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
![Page 8: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/8.jpg)
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
![Page 9: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/9.jpg)
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
![Page 10: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/10.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 11: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/11.jpg)
Overview
Entities
Value Objects
Enumerations
Logic
Exceptions
Join the Conversation #GOTOCph @JasonGtAu
Presentation
Application
Infrastructure
Domain
![Page 12: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/12.jpg)
Demo
Reviewing the Domain layer
Join the Conversation #GOTOCph @JasonGtAu
![Page 13: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/13.jpg)
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
![Page 14: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/14.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 15: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/15.jpg)
Overview
Interfaces
Models
Logic
Commands / Queries
Validators
Exceptions
Join the Conversation #GOTOCph @JasonGtAu
Presentation
Application
Infrastructure
Domain
![Page 16: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/16.jpg)
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
![Page 17: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/17.jpg)
CQRS + MediatR = ♥
Define commands and queries as requests
Application layer is just a series of request / response
objects
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
![Page 18: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/18.jpg)
Demo
Reviewing the Application layer
Join the Conversation #GOTOCph @JasonGtAu
![Page 19: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/19.jpg)
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
![Page 20: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/20.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 21: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/21.jpg)
Overview
Persistence
Identity
File System
System Clock
API Clients
Join the Conversation #GOTOCph @JasonGtAu
Presentation
Application
Infrastructure
Domain
![Page 22: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/22.jpg)
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
![Page 23: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/23.jpg)
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-workpattern isn’t useful with EFCore.
No, you don’t need a repository.But there are many benefitsand you should consider it!
![Page 24: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/24.jpg)
Demo
Reviewing the Infrastructure layer
Join the Conversation #GOTOCph @JasonGtAu
![Page 25: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/25.jpg)
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
![Page 26: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/26.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 27: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/27.jpg)
Overview
SPA – Angular, React, Vue
Web API
Razor Pages
MVC
Web Forms
Join the Conversation #GOTOCph @JasonGtAu
Presentation
Application
Infrastructure
Domain
![Page 28: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/28.jpg)
Demo
Reviewing the Presentation layer
Join the Conversation #GOTOCph @JasonGtAu
![Page 29: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/29.jpg)
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
![Page 30: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/30.jpg)
Clean Architecture
Infrastructure Layer
Application Layer
Presentation Layer
Next Steps
Domain Layer
Agenda
![Page 31: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/31.jpg)
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>
![Page 32: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/32.jpg)
Join the Conversation #GOTOCph @JasonGtAu
![Page 33: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/33.jpg)
Join the Conversation #GOTOCph @JasonGtAu
![Page 34: Clean Architecture - GOTO Conference · 2019-11-22 · ASP.NET Core Identity 3.0 Repo bit.ly/ca-sln Join the Conversation #GOTOCph @JasonGtAu. Domain contains enterprise-wide logic](https://reader036.vdocument.in/reader036/viewer/2022070906/5f77788840a08940a854c68c/html5/thumbnails/34.jpg)
Thank you!
www.ssw.com.au
Sydney | Melbourne | Brisbane
@jasongtau
bit.ly/ca-sln
bit.ly/northwind-traders