The simplest demo on how to implement a Web Api using .NET Core and Entity Framework that protects the business rules from framework dependencies by following the Clean Architecture Principles.
docker run -e ASPNETCORE_ENVIRONMENT="Development" -p 5500:80 ivanpaulovich/clean-architecture-webapi-ef-core
To run on top of a InMemory persistance layer simple run:
dotnet run --environment="dev" --project source/MyWallet.WebApi/MyWallet.WebApi.csproj
To run on top of a SQL Server persistance layer you need to setup the SQL Server database in steps ahead then run:
dotnet run --environment="production" --project source/MyWallet.WebApi/MyWallet.WebApi.csproj
Then navigate to the Swagger URL http://localhost:5500/
or run in command-line:
curl -X POST "http://localhost:5500/api/Customers" -H "accept: application/json" -H "Content-Type: application/json-patch+json" -d "{ \"personnummer\": \"198608178877\", \"name\": \"string\", \"initialAmount\": 440}"
If you wanna use Entity Framework, setup the SQL Server then update the database via dotnet EF Tool.
dotnet ef database update --project source/MyWallet.Infrastructure --startup-project source/MyWallet.WebApi
Run the EF Tool to add a migration to the MyWallet.Infrastructure
project.
dotnet ef migrations add "InitialCreate" -o "EntityFrameworkDataAccess/Migrations" --project source/MyWallet.Infrastructure --startup-project source/MyWallet.WebApi
To run SQL Server container images with Docker use:
#!/bin/bash
sudo docker pull mcr.microsoft.com/mssql/server:2017-latest
sudo docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=<YourStrong!Passw0rd>' -p 1433:1433 --name sql1 -d mcr.microsoft.com/mssql/server:2017-latest
sudo docker exec -it sql1 /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P '<YourStrong!Passw0rd>' -Q 'ALTER LOGIN SA WITH PASSWORD="<YourNewStrong!Passw0rd>"'
It will enable a SQL Server running on Server=localhost;User Id=sa;Password=<YourNewStrong!Passw0rd>;
for more details checkout the docs at How to run a SQL Server in a Docker Container.
Developed and Tested using:
- MacOS Sierra
- VSCode ❤️
- .NET SDK 2.2.
- Docker 🐳
- SQL Server via Docker container.
I am happy to be reach out through the Issues Tab.