Skip to content

stephen60606/ASPDotNETCore-WebAPI-Sample-.netCore

Repository files navigation

dotnet_api_basic_structure

This basic api structure designed for saving time on developing every new project and could fulfill decouled and APO design.

                  Client
                    ⬇
            NetCore MiddleWare
                    ⬇
                  WebAPI
                    ⬇
               FeatureModule
                    ⬇
                 Database

Here is the structure design pattern. When receive a request, the first layer dealling with the request is Middleware which can fulfill the AOP design here, then calling the method in WebAPI depending on the route. In the FeatureModule, the interface can offer different services for different environments, and this is where we deal with business logic.


Generating model and dbContext in Entities:

for inite, add this code in "Entities/Context/DemoDbContext.cs": Screenshot 2023-08-03 at 1 42 03 AM

then follow these steps:

dotnet tool install --global dotnet-ef

dotnet add package Pomelo.EntityFrameworkCore.MySql

dotnet add package Microsoft.EntityFrameworkCore.Design

//MySql dotnet ef dbcontext scaffold "server=localhost;Port=3306;Database=Demo_db; User=;Password=;" "Pomelo.EntityFrameworkCore.MySql" --output-dir Models --context-dir Contexts --context DemoDbContext -f

//MSSql dotnet ef dbcontext scaffold "Data Source=;Initial Catalog=; Persist Security Info=True;User ID=;Password=" Microsoft.EntityFrameworkCore.SqlServer --output-dir Models --context-dir Contexts --context DemoDbContext -f


Here is my DB Schema of mysql for this basic project:

Screenshot 2023-08-05 at 2 33 49 AM