Skip to content

ntijoh-ola-lindberg/dotnet-be-todo-o-matic

Repository files navigation

.NET backend for Todo-o-matic

Backend using .NET v7 with Postgres DB running in Docker.
Demo project that replaces Todo-o-matic Sinatra backend.


Install + getting started

  1. Install .NET 7 SDK (Software Developer Kit): brew install dotnet-sdk

  2. Create demo project:

    dotnet new webapi -o TodoApi 
    cd TodoApi 
    dotnet add package Microsoft.EntityFrameworkCore.InMemory 
    code ../TodoApi
    
  3. 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.

  4. Install Docker: brew install —cask docker

  5. 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

  6. Install Postgress Entity Framework Core provider with NuGet: dotnet add package Npgsql.EntityFrameworkCore.PostgreSQL

  7. Change in Program.cs to use the Npgsql instead of inmemory db.

  8. Create your model files. See this demo project.

  9. Generate and run DB migration files from modell classes

    dotnet tool install --global dotnet-ef
    dotnet ef migrations add InitialCreate
    dotnet ef database update
    
  10. 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

Tools

About

Dotnet backend with Postgres database running in Docker

Resources

License

Stars

Watchers

Forks

Languages