This repository demonstrate how to connect web api to distributed database in dotnet core web api 3.0.
Install the following dotnet core 3.0 sdk
My preferred editor is visual studio code
The project involves doing the following
- Store User entity in a Postgres database
- Store Book entity in Microsoft Sql Server database (MSSQL)
verb | Endpoint | description | body |
---|---|---|---|
POST | /api/user | adds a dummy user |
{ "FirstName": "John","LastName" : "Doe"} |
GET | /api/user | gets all dummy user |
None |
POST | /api/book | adds a dummy book |
{ "ISBN": 16657", Author": "Learning Dollars"} |
GET | /api/book | gets all dummy books |
None |
-
provision a database instance on MSSQL.
-
provision a database instance on PostgresDB
-
add the connnection strings to appsettings.json in the following format below.
note appsettings.json must be in the project root directory
"ConnectionStrings": {
"UserDBConnection"postgres connection string",
"DefaultConnection": "mssql connection string"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
}
- dotnet restore
dotnet ef database update --context UserDbContext
dotnet ef database update --context BookDbContext
- dotnet run build