ASP.NET Core
Clean Architecture

 

Gökhan GÖKALP

09.28.2019

.NET Conf 2019 Turkey

Best practices for Clean Code built with ASP.NET Core

.NET Conf

September 28, 2019

Who am I?

Gökhan GÖKALP
Software Architect


 

http://www.gokhan-gokalp.com

E-mail: gok.gokalp@yahoo.com
LinkedIn: in/gokgokalp

Twitter: @gokgokalp
GitHub: gokgokalp

Maintenance is more expensive than actually building the software.

 

" Good architecture makes the system easy to understand, easy to develop, easy to maintain, and easy to deploy. The ultimate goal is to minimize the lifetime cost of the system and to maximize programmer productivity. "

 Robert C. Martin, Clean Architecture

 

" The way you keep software soft is to leave as many options open as possible, for as long as possible. What are the options that we need to leave open? They are the details that don’t matter. "

Robert C. Martin, Clean Architecture

Coupling?

Coupling is a measure of the degree of dependence between modules.

  • Loosely coupling
  • Tightly coupling

Modules should not be tightly coupled to each other.

- is important for Clean Architecture

Separation of Concerns

Separation of concerns is a core principle while designing a good architectures.

Single Responsibility?

The goal is to prevent handling different concerns, in one place.

Business logics

           DB operations

                                 UI?

I love spaghetti when I can eat it.

Separation of Concerns

A good design should be:

Single Responsibility?

  • Easy to maintain
  • Less coupled
  • Easy to extend

Important for layered architecture.

Layered Architecture

Separation of Concerns

Dependency flow

Layered Architecture

Separation of Concerns

Dependency flow

Hierarchy?

Layers are dependent on each other

Layered Architecture

Separation of Concerns

Dependency flow

Hierarchy?

How can we achieve more decoupling between layers?

Layered Architecture

Separation of Concerns

Dependency flow

Hierarchy?

Dependency Inversion Principle

Dependency Inversion Principle

Uncle Bob's "Clean Architecture" concept.

Alistair Cockburn's "Hexagonal Architecture". 

Domain-centric design

Core

Dependencies point only inwards

Clean Architecture?

Clean architecture is an overall project design that includes a set of best practices.

Why Clean Architecture?

  • Hard to change
    • ​New features
    • Maintenance?
  • It's hard to test
    • Duplication
    • Tightly coupled
    • Fragility
    • Possibble side effects
  • Independent of databases, frameworks, and external libraries
    • Application domain should stay pure
    • ​Flexibility

Why Clean Architecture?

Why Clean Architecture?

  • Testability
    • We should be able to test each component easily and independently
  • Maintainability
  • Extendability
    • We should be able to extend or add new modules to the system without causing any problem
  • ​​Reusability
  • Readability
 

Well...

Why Clean Architecture?

Clean Architecture is not a silver bullet

Concepts

Hexagonal architecture is an instance of Clean Architecture.

Core layer

Adapters

Isolated

Concepts

Entities

  • Business objects of an application.
  • Should not be affected by anything.

Use-Cases

  • These are business actions (Independent services).
  • They implement and encapsulate business rules.
  • Each use-case follows the single responsibility principle.
  • Use-cases do not care where the data comes from.
  • Use-cases use output ports to persist/manage data.

Concepts

Concepts

More clear?

Concepts

Interfaces/Adapters

  • These are implementations of interfaces that we define in the core layer.
  • It can be a part that will be responsible for saving or retrieving data.

To be able to invert dependencies

Adapter

Isolated &
decoupled

Code time!

References

Contacts

ASP.NET Core Clean Architecture

By Gökhan Gökalp

ASP.NET Core Clean Architecture

Best practices for Clean Code built with ASP.NET Core - .NET Conf 2019 Turkey

  • 2,479