003 Generate Backend - CarrieKroutil/Reactivities GitHub Wiki
Using .NET CLI
In terminal, create demo folder: mkdir demo
→ cd demo
Add the following script to spin up new set of projects:
- Prerequisite: .NET SDK has been installed to have access to the .NET CLI (via dotnet)
MacOS Script
- For macOS - name file create-projects-osx.sh with the following contents:
#!/usr/bin/env bash
green="\033[1;32m"
reset="\033[m"
echo "About to create the directory"
mkdir Reactivities
cd Reactivities
echo -e "${green}Creating solution and projects${reset}"
dotnet new sln
dotnet new webapi -n API
dotnet new classlib -n Application
dotnet new classlib -n Domain
dotnet new classlib -n Persistence
echo -e "${green}Adding projects to the solution${reset}"
dotnet sln add API/API.csproj
dotnet sln add Application/Application.csproj
dotnet sln add Domain/Domain.csproj
dotnet sln add Persistence/Persistence.csproj
echo -e "${green}Setting up project dependancies${reset}"
cd API
dotnet add reference ../Application/Application.csproj
cd ../Application
dotnet add reference ../Domain/Domain.csproj
dotnet add reference ../Persistence/Persistence.csproj
cd ../Persistence
dotnet add reference ../Domain/Domain.csproj
cd ..
echo -e "${green}Executing dotnet restore${reset}"
dotnet restore
echo -e "${green}Finished!${reset}"
- On Mac, give permission to run script:
chmod +x create-projects-osx
- Run script to generate solution with projects:
./create-projects-osx.sh
- Run script to generate solution with projects:
Windows Script
- For Windows - name file create-projects-win.ps1 with the following contents:
Write-Host "About to Create the directory" -ForegroundColor Green
mkdir Reactivities
cd Reactivities
Write-Host "About to create the solution and projects" -ForegroundColor Green
dotnet new sln
dotnet new webapi -n API
dotnet new classlib -n Application
dotnet new classlib -n Domain
dotnet new classlib -n Persistence
Write-Host "Adding projects to the solution" -ForegroundColor Green
dotnet sln add API/API.csproj
dotnet sln add Application/Application.csproj
dotnet sln add Domain/Domain.csproj
dotnet sln add Persistence/Persistence.csproj
Write-Host "Adding project references" -ForegroundColor Green
cd API
dotnet add reference ../Application/Application.csproj
cd ../Application
dotnet add reference ../Domain/Domain.csproj
dotnet add reference ../Persistence/Persistence.csproj
cd ../Persistence
dotnet add reference ../Domain/Domain.csproj
cd ..
Write-Host "Executing dotnet restore" -ForegroundColor Green
dotnet restore
Write-Host "Finished!" -ForegroundColor Green
View App in VSCode
Open new folder called “Reactivities” that was created inside demo: cd Reactivities
.
To see the new projects, type: dotnet sln list
.
Once inside code folder, open VSCode: code .
Reactivities now contains:
Project Structure
The application architecture used puts the Domain project at the core, where the API knows about to the Application, which can talk to the Domain or Persistence, that then can talk to the Domain. To visualize:
flowchart LR
A(API) --> B(Application)
B --> C(Domain)
B --> D(Persistence)
D --> C
The key takeaway is that the Domain project is at the center of everything, and has no dependancies on anything else.
Launch API
To run: cd api
→ dotnet run
.