bogarin / Practical.CleanArchitecture

Asp.Net Core 3.1 samples (+ Angular 9.0, React 16.13, Vue 2.6) with modern Clean Architecture, Domain-Driven Design, CQRS, Event Sourcing, SOLID, Asp.Net Core Identity Custom Storage, Identity Server 4 Admin UI, Entity Framework Core, Blazor, Selenium E2E Testing, SignalR Notification, Hangfire Tasks Scheduling, Health Checks, Security Headers, ...

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Domain-Driven Design Path | 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:

Update Configuration

Database
  • Update Connection Strings:

    Project Configuration File Configuration Key
    ClassifiedAds.Migrator appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.BackgroundServer appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.IdentityServer appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.WebAPI appsettings.json ConnectionStrings:ClassifiedAds
    ClassifiedAds.WebMVC appsettings.json ConnectionStrings:ClassifiedAds
  • 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
        
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"
      }
    },
Message Broker
  • Open ClassifiedAds.WebMVC/appsettings.json and ClassifiedAds.BackgroundServer/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"
      }
    }
Logging
  • Open and jump to LoggerOptions section of below files:
    "LoggerOptions": {
      "File": {
        "MinimumLogEventLevel": "Information"
      },
      "Elasticsearch": {
        "IsEnabled": false,
        "Host": "http://localhost:9200",
        "IndexFormat": "classifiedads",
        "MinimumLogEventLevel": "Information"
      },
      "EventLog": {
        "IsEnabled": false,
        "LogName": "Application",
        "SourceName": "ClassifiedAds.WebAPI"
      }
    },
  • Write to Local file (./logs/log.txt). Always enabled.
    "LoggerOptions": {
      "File": {
        "MinimumLogEventLevel": "Information"
      },
    },
  • Write to Elasticsearch:
    "LoggerOptions": {
      "Elasticsearch": {
        "IsEnabled": true,
        "Host": "http://localhost:9200",
        "IndexFormat": "classifiedads",
        "MinimumLogEventLevel": "Information"
      },
    },
  • Write to Windows Event Log (Windows only):
    "LoggerOptions": {
      "EventLog": {
        "IsEnabled": true,
        "LogName": "Application",
        "SourceName": "ClassifiedAds.WebAPI"
      }
    },
  • Enable all options:
    "LoggerOptions": {
      "File": {
        "MinimumLogEventLevel": "Information"
      },
      "Elasticsearch": {
        "IsEnabled": true,
        "Host": "http://localhost:9200",
        "IndexFormat": "classifiedads",
        "MinimumLogEventLevel": "Information"
      },
      "EventLog": {
        "IsEnabled": true,
        "LogName": "Application",
        "SourceName": "ClassifiedAds.WebAPI"
      }
    },

Set Startup Projects

alt text

Run or Debug the Solution

How to Build and Run Single Page Applications:

How to Run on Docker Containers:

Application URLs:

Project Launch URL Docker Container URL Docker Container URL
BackgroundServer https://localhost:44318 http://localhost:9004 http://host.docker.internal:9004
Blazor https://localhost:44331 http://localhost:9008 http://host.docker.internal:9008
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

About

Asp.Net Core 3.1 samples (+ Angular 9.0, React 16.13, Vue 2.6) with modern Clean Architecture, Domain-Driven Design, CQRS, Event Sourcing, SOLID, Asp.Net Core Identity Custom Storage, Identity Server 4 Admin UI, Entity Framework Core, Blazor, Selenium E2E Testing, SignalR Notification, Hangfire Tasks Scheduling, Health Checks, Security Headers, ...


Languages

Language:C# 48.3%Language:JavaScript 23.8%Language:HTML 22.3%Language:TypeScript 1.9%Language:Dockerfile 1.6%Language:CSS 1.3%Language:Vue 0.7%Language:PowerShell 0.1%