Skip to content

Latest commit

 

History

History
226 lines (185 loc) · 9.43 KB

README.md

File metadata and controls

226 lines (185 loc) · 9.43 KB

Clean Architecture: Patterns, Practices, and Principles | Matthew Renze | Pluralsight

Database Centric vs Domain Centric Architecture

alt text

(open on draw.io)

Hexagonal Architecture

alt text

(open on draw.io)

Onion Architecture

alt text

(open on draw.io)

The Clean Architecture

alt text

(open on draw.io)

Classic Three-layer Architecture

alt text

(open on draw.io)

Modern Four-layer Architecture

alt text

(open on draw.io)

Layer Dependencies

alt text

(open on draw.io)

Layer Examples

alt text

(open on draw.io)

Solution Structure

alt text

How to Run:

Configure Database

  • Update Connection Strings:

    Project Configuration File Configuration Key
    ClassifiedAds.Migrator appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.BackgroundServices appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.GRPC appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.IdentityServer appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.NotificationServer appsettings.json
    ClassifiedAds.WebAPI appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.WebMVC appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.GraphQL appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.Ocelot appsettings.json
  • Run Migration:

    • Option 1: Using dotnet cli:
      • Install dotnet-ef cli:
        dotnet tool install --global dotnet-ef --version="3.1"
        
      • Navigate to ClassifiedAds.Migrator and run these commands:
        dotnet ef migrations add Init --context AdsDbContext -o Migrations/AdsDb
        dotnet ef migrations add Init --context ConfigurationDbContext -o Migrations/ConfigurationDb
        dotnet ef migrations add Init --context PersistedGrantDbContext -o Migrations/PersistedGrantDb
        dotnet ef database update --context AdsDbContext
        dotnet ef database update --context ConfigurationDbContext
        dotnet ef database update --context PersistedGrantDbContext
        
    • Option 2: Using Package Manager Console:
      • Set ClassifiedAds.Migrator as StartUp Project
      • Open Package Manager Console, select ClassifiedAds.Migrator as Default Project
      • Run these commands:
        Add-Migration -Context AdsDbContext Init -OutputDir Migrations/AdsDb
        Add-Migration -Context ConfigurationDbContext Init -OutputDir Migrations/ConfigurationDb
        Add-Migration -Context PersistedGrantDbContext Init -OutputDir Migrations/PersistedGrantDb
        Update-Database -Context AdsDbContext
        Update-Database -Context ConfigurationDbContext
        Update-Database -Context PersistedGrantDbContext
        

Configure Storage

  • Open ClassifiedAds.WebMVC/appsettings.json and jump to Storage section.

    "Storage": {
      "Provider": "Local",
    },
  • Use Local Files:

    "Storage": {
      "Provider": "Local",
      "Local": {
        "Path": "E:\\files"
      },
    },
  • Use Azure Blob:

    "Storage": {
      "Provider": "Azure",
      "Azure": {
        "ConnectionString": "xxx",
        "Container": "classifiedadds"
      },
    },
  • Use Amazon S3:

    "Storage": {
      "Provider": "Amazon",
      "Amazon": {
        "AccessKeyID": "xxx",
        "SecretAccessKey": "xxx",
        "BucketName": "classifiedadds",
        "RegionEndpoint": "ap-southeast-1"
      }
    },

Configure Message Broker

  • Open ClassifiedAds.WebMVC/appsettings.json and jump to MessageBroker section.

    "MessageBroker": {
      "Provider": "RabbitMQ",
    }
  • Use RabbitMQ

    "MessageBroker": {
      "Provider": "RabbitMQ",
      "RabbitMQ": {
        "HostName": "localhost",
        "UserName": "guest",
        "Password": "guest",
        "ExchangeName": "amq.direct",
        "RoutingKey_FileUploaded": "classifiedadds_fileuploaded",
        "RoutingKey_FileDeleted": "classifiedadds_filedeleted",
        "QueueName_FileUploaded": "classifiedadds_fileuploaded",
        "QueueName_FileDeleted": "classifiedadds_filedeleted"
      },
    }
  • Use Kafka:

    "MessageBroker": {
      "Provider": "Kafka",
      "Kafka": {
        "BootstrapServers": "localhost:9092",
        "Topic_FileUploaded": "classifiedadds_fileuploaded",
        "Topic_FileDeleted": "classifiedadds_filedeleted"
      },
    }
  • Use Azure Queue Storage:

    "MessageBroker": {
      "Provider": "AzureQueue",
      "AzureQueue": {
        "ConnectionString": "xxx",
        "QueueName_FileUploaded": "classifiedadds-fileuploaded",
        "QueueName_FileDeleted": "classifiedadds-filedeleted"
      },
    }
  • Use Azure Service Bus:

    "MessageBroker": {
      "Provider": "AzureServiceBus",
      "AzureServiceBus": {
        "ConnectionString": "xxx",
        "QueueName_FileUploaded": "classifiedadds_fileuploaded",
        "QueueName_FileDeleted": "classifiedadds_filedeleted"
      }
    }

Set Startup Projects

alt text

Run or Debug the Solution

alt text

alt text

How to Login on Identity Server:

Application URLs:

Project Launch URL Docker Container URL Docker Container URL
BackgroundServices https://localhost:44318 http://localhost:9004 http://host.docker.internal:9004
GRPC https://localhost:5001 https://localhost:9005 https://host.docker.internal:9005
IdentityServer https://localhost:44367 http://localhost:9000 http://host.docker.internal:9000
NotificationServer https://localhost:44390 http://localhost:9001 http://host.docker.internal:9001
WebAPI https://localhost:44312 http://localhost:9002 http://host.docker.internal:9002
WebMVC https://localhost:44364 http://localhost:9003 http://host.docker.internal:9003
GraphQL https://localhost:44392 http://localhost:9006 http://host.docker.internal:9006
Ocelot https://localhost:44340 http://localhost:9007 http://host.docker.internal:9007