Skip to content

Latest commit

 

History

History
201 lines (123 loc) · 8.93 KB

File metadata and controls

201 lines (123 loc) · 8.93 KB

Anotações do curso

Developing Ordering Microservices with Clean Architecture and CQRS Implemntation

Introdução

Implementar Ordering.API com Clean Architecture e CQRS:

Big Picture

Analysis and Architecting of Ordering Microservices

Ordering REST APIs

Method Request URI Use Case
GET api/v1/Order Get Orders with username
  • Get Orders with username
  • Consume basketCheckout event from RabbitMQ
  • CQRS implementation with triggering OrderCommand to insert Order record

Ordering Architecture

Simplified CQRS and DDD microservice - High level desing

Architecture of Ordering Microservices

Design Principles - SOLID

Design Principles - SOLID

Design Principles - Dependency Inversion Principles (DIP)

Dependency Inversion Principles (DIP)

Design Principles - Separation of Concerns (SoC)

Separation of Concerns (SoC)

Domain Driven Design - DDD

Domain Driven Design - DDD

Clean Architecture with Domain Driven Design (DDD)

Clean Architecture

Clean Architecture

CQRS (Command Query Responsibility Segregation) Design Pattern

CQRS (Command Query Responsibility Segregation) Design Pattern

Eventual Consistency and Event Sourcing with CQRS Design Pattern

Eventual Consistent

Event Sourcing

CQRS and Event Sourcing

Code Structure on CQRS and DDD Implementation in Ordering Microservices

Simplified CQRS and DDD microservice - High level design

Code Structure of Ordering Microservices

Ordering.Domain Nuget Packages

  • Nenhum pacote nuget

Ordering.Application Nuget Packages

Ordering.Infrastructure Nuget Packages

Ordering.API Nuget Packages

Menções

Menções do instrutor, duas pessoas que possuem ótimos repositórios/materiais para referência.

Menções

Jason Taylor Gill Cleeren
Repositório GitHub: CleanArchitecture Twitter
YouTube: Clean Architecture with ASP.NET Core 3.0 - Jason Taylor - NDC Sydney 2019 YouTube: Gill CLEEREN: Clean architecture with ASP.NET Core UCP2019

Create Asp.Net Web Api Project for Ordering.API Microservice

Adicionado novo projeto "Ordering.API" em "src/Services/Ordering" com o comando:

dotnet new webapi --exclude-launch-settings --no-https --auth None -o Ordering.API

Configurado ".vscode/launch.json" para utilizar a porta 5004

Create Clean Architecture Layers that Ordering Domain - Application and Infra

Adicionado novos projetos "Ordering.Domain", "Ordering.Application" e "Ordering.Infrastructure" em "src/Services/Ordering" com os comandos:

dotnet new classlib -o Ordering.Domain
dotnet new classlib -o Ordering.Application
dotnet new classlib -o Ordering.Infrastructure

Obs.: Devido a estar utilizando vscode com net core cli, precisei adicionar os novos projetos todas a solution com os comandos executados na pasta "src":

dotnet sln add ./Services/Ordering/Ordering.API
dotnet sln add ./Services/Ordering/Ordering.Domain
dotnet sln add ./Services/Ordering/Ordering.Application
dotnet sln add ./Services/Ordering/Ordering.Infrastructure

Adding Project References Between Clean Architecture Layers

Adicionadas as referências entre projetos com dotnet cli, executando os seguintes comandos na pasta "src/Services/Ordering":

# Adiciona uma referência do projeto "Domain" no projeto "Application"
dotnet add ./Ordering.Application/Ordering.Application.csproj reference ./Ordering.Domain/Ordering.Domain.csproj

# Adiciona uma referência do projeto "Application" no projeto "Infrastructure"
dotnet add ./Ordering.Infrastructure/Ordering.Infrastructure.csproj reference ./Ordering.Application/Ordering.Application.csproj

# Adiciona uma referência do projeto "Application" no projeto "API"
dotnet add ./Ordering.API/Ordering.API.csproj reference ./Ordering.Application/Ordering.Application.csproj

# Adiciona uma referência do projeto "Infrastructure" no projeto "API"
dotnet add ./Ordering.API/Ordering.API.csproj reference ./Ordering.Infrastructure/Ordering.Infrastructure.csproj

CQRS Implementation with Mediator Design Pattern

Mediator Design Pattern

MediatT Nuget Package

MediatR Pipeline Behavior

High Level "Writes-side" in CQRS

Developing Ordering.Infrastructure Layer in Clean Architecture - Persistence

Adicionados os pacotes nuget SendGrid e Microsoft.EntityFrameworkCore.SqlServer em Ordering.Infrastructure:

dotnet add package SendGrid
dotnet add package Microsoft.EntityFrameworkCore.SqlServer

Adding EF Core Migrations for Code-First Approach in Ordering Microservices

Adicionados o pacote nuget Microsoft.EntityFrameworkCore.Tools em Ordering.API:

dotnet add package Microsoft.EntityFrameworkCore.Tools

O instrutor usou o comando Add-Migration InitialCreate em Ordering.Infrastructure, porém como estou utilizando preciso adicionar a tool dotnet-ef (de preferência global, mas vou adicionar no projeto para ficar registrado em .config) e para isso vou executar na pasta AspnetMicroservices o comando:

dotnet tool install dotnet-ef

E agora para criar a migration vou executar em AspnetMicroservices/src/Services/Ordering/Ordering.Infrastructure:

dotnet tool run dotnet-ef migrations add InitialCreate --startup-project '../Ordering.API/Ordering.API.csproj'

# Obs.: se a tool estivesse instalada globalmente eu poderia executar o seguinte comando (um pouco menor)
# dotnet ef migrations add InitialCreate --startup-project '../Ordering.API/Ordering.API.csproj'

Adding SqlServer image into Docker-Compose File for Multi-Container Docker Env

Adiciona a imagem Microsoft SQL Server no docker-compose.

Test and Run Ordering Microservice

Para visualizar o banco o instrutor utilizou o ServerExplorer do VisualStudio, porém como estou utilizando vscode, eu utilizei a extensão SQLTools com o driver SQLTools Microsoft SQL Server/Azure.