Backend using .NET v7 with Postgres DB running in Docker.
Demo project that replaces Todo-o-matic Sinatra backend.
-
Install .NET 7 SDK (Software Developer Kit):
brew install dotnet-sdk
-
Create demo project:
dotnet new webapi -o TodoApi cd TodoApi dotnet add package Microsoft.EntityFrameworkCore.InMemory code ../TodoApi
-
Complete guide for installing .NET with demo project: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-7.0&preserve-view=true&tabs=visual-studio From this guide you must create the Model, Context file + scaffold the controller. You also must add the certs for https.
-
Install Docker:
brew install —cask docker
-
Install Postgres Docker image: https://hackernoon.com/dont-install-postgres-docker-pull-postgres-bee20e200198
Start Docker container with persistent data on disk:
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=docker -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
-
Install Postgress Entity Framework Core provider with NuGet:
dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL
-
Change in Program.cs to use the Npgsql instead of inmemory db.
-
Create your model files. See this demo project.
-
Generate and run DB migration files from modell classes
dotnet tool install --global dotnet-ef dotnet ef migrations add InitialCreate dotnet ef database update
-
Add CORS exception for localhost: https://learn.microsoft.com/en-us/aspnet/core/security/cors?view=aspnetcore-7.0#cors-with-named-policy-and-middleware
-
Test your web service with Swagger: http://localhost:5232/swagger/index.html
-
PostgreSQL Management Tool för VSCode: https://marketplace.visualstudio.com/items?itemName=ckolkman.vscode-postgres
-
C# REPL: https://github.com/waf/CSharpRepl
-
Uninstall tool for .NET: https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool?tabs=macos