Last active
March 16, 2023 09:08
-
-
Save TheAnarchoX/28f1dc26f52f453d10ebac7d862c6d6b to your computer and use it in GitHub Desktop.
generate DDD skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Default values | |
solution_name="YourSolutionName" | |
target_directory="." | |
# Parse command-line options | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-n|--name) | |
solution_name="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-t|--target) | |
target_directory="$2" | |
shift # past argument | |
shift # past value | |
;; | |
*) | |
shift # past unknown option | |
;; | |
esac | |
done | |
target_directory="$target_directory/$solution_name" | |
# Create solution folders | |
mkdir -p $target_directory/{$solution_name.Domain,$solution_name.Application,$solution_name.Infrastructure,$solution_name.UI} | |
# Initialize the solution file | |
dotnet new sln -n $solution_name -o $target_directory | |
# Initialize projects and add them to the solution | |
for project in Domain Application Infrastructure UI; do | |
project_path="$target_directory/$solution_name.$project" | |
dotnet new classlib -n "$solution_name.$project" -o "$project_path" | |
dotnet sln $target_directory/$solution_name.sln add "$project_path/$solution_name.$project.csproj" | |
done | |
# Create Domain subdirectories | |
mkdir -p $target_directory/$solution_name.Domain/{Entities,ValueObjects,Aggregates,Repositories,DomainEvents,DomainServices} | |
# Create Application subdirectories | |
mkdir -p $target_directory/$solution_name.Application/{ApplicationServices,DTOs,Interfaces,Mappings,Validators} | |
# Create Infrastructure subdirectories | |
mkdir -p $target_directory/$solution_name.Infrastructure/{Repositories,Persistence/{Migrations,Configuration},ExternalServices,Messaging/{EventHandlers},IoC} | |
# Create UI subdirectories | |
mkdir -p $target_directory/$solution_name.UI/{Controllers,Views/{Customer,Order},ViewModels,StaticFiles/{css,js},Middlewares} | |
# Create sample Startup.cs | |
touch $target_directory/$solution_name.UI/Startup.cs | |
echo "Directory structure and solution file created for $solution_name at $target_directory." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment