eCommerce application from past 15 years
Traditional monolithic design - Introduction to cloud-native applications | Microsoft Learn
Native
= พื้นเมือง
Cloud Native
= “คลาวไทยบ้าน”
= ไทยบ้าน ในภาษาอีสาน
Cloud Native
eCommerce application adopting a cloud-native approach
“ There was a lot of techniques/configuration ”
“ Provide minimal components for resiliency defaults, health checks, telemetry, and integrate with DI ”
Install .NET Aspire
To work with .NET Aspire, you'll need the following installed locally:
.NET Aspire Component
Components are glue libraries that configure an SDK to operate in a cloud environment
dotnet add package Aspire.RabbitMQ.Client --prerelease
+Host Project: var rabbit = builder.AddRabbitMQContainer("rabbit");
+ServiceDefaults Project
Aspire.RabbitMQ.Client
Common service-centric logic
that applies across all the projects
Microsoft.Extensions.ServiceDiscovery
Healthcheck
Logging
.NET Aspire References
เห็นคำว่า Clean แล้วนึกถึงอะไร
Robert C. Martin (Uncle Bob)
Clean Code
“เน้นไปที่รายละเอียดของโค้ด
ที่ทำความเข้าใจง่าย ดูแลรักษาง่าย”
Clean Architecture
“เน้นไปที่การออกแบบระบบโดยรวม
ที่เน้นความยืดหยุ่น รองรับการเปลี่ยนแปลง ทดสอบง่าย”
“ทั้งสองล้วนจำเป็นในการสร้างซอฟต์แวร์คุณภาพและบำรุงรักษาได้ดีในระยะยาว”
Clean Code
Traditional "N-Layer" architecture applications
มันก็ทำงานได้นะ แล้วทำไมเราต้องมี �Clean Architecture
พี่ขอเปลี่ยนฐานข้อมูล
จาก MySQL
เป็น MSSQL
น่าจะใช้เวลาแก้ไม่นาน
ใช่ไหมครับ
ลูกค้า
ผู้น่าร้ากกก
Developer ท่านนึง
“Dividing the software into layers for separation of concerns”
Clean Architecture - Uncle Bob
ยังไม่เสร็จ T_T
Dependency Non-Injection
“New is Glue.”
Interface
Dependency
Injection (DI)
IoC Container (DI Container):
1.Transient Instance จะถูกสร้างใหม่ทุกครั้งที่มีการเรียกใช้งานภายในระบบ
เหมาะสำหรับการทำงานที่ Lightweight, Stateless
2. Scoped Instance จะถูกสร้างใหม่ทุกครั้งที่ Client Request เข้ามานะครับ (1 Connection = 1 Client Request)
เหมาะสำหรับการทำงานที่ต้องการเรื่องของ Stateful เช่น Entity Framework (AddDbContext)
3. Singleton Instance จะถูกสร้างแค่ครั้งแรกที่ถูกเรียก หลังจากนั้น Instance จะคงอยู่ตลอดไปจนกว่าเราจะปิดและเปิดระบบขึ้นมาใหม่ เหมาะสำหรับบางงานที่ต้องการ Reuse Instance เดิมอยู่ตลอด เช่น Logging, Caching
Project
Domain
Project
Core
Project
Infra
Project API