- Create the solution: dotnet new sln -n MySolution
- Create the ASP.NET Core Web API project: dotnet new webapi -n MyAPI
- Create the xUnit Test Project: dotnet new xunit -n MyAPI.Tests
- Add projects into the solution:
- dotnet sln MySolution.sln add MyAPI/MyAPI.csproj
- dotnet sln MySolution.sln add MyAPI.Tests/MyAPI.Tests.csproj
- Add API reference into the xUnit project:
- dotnet add MyAPI.Tests/MyAPI.Tests.csproj reference MyAPI/MyAPI.csproj
ASP.NET already includes the Microsoft.Extensions.Logging
To use the Serilog, add the following packages:
- dotnet add MyAPI package Serilog.AspNetCore
- dotnet add MyAPI package Serilog.Sinks.Console
- dotnet add MyApi package Microsoft.EntityFrameworkCore.Sqlite
- dotnet add MyApi package Microsoft.EntityFrameworkCore.Design
- dotnet add MyAPI package Microsoft.AspNetCore.Mvc.Core
Add into MyAPI Program.cs or Startup.cs
builder.Services.AddDbContext<AppDbContext>(options =>options.UseSqlite("Data Source=app.db"));Create the AppDbContext:
publicclassAppDbContext:DbContext{publicAppDbContext(DbContextOptions<AppDbContext>options):base(options){}publicDbSet<MyEntity>MyEntities{get;set;}}publicclassMyEntity{publicintId{get;set;}publicstringName{get;set;}}Run EF Core migrations
- dotnet ef migrations add InitialCreate --project MyApi
- dotnet ef database update --project MyApi
Install the CLI program
- dotnet tool install --global dotnet-ef