Skip to content

Latest commit

 

History

History
90 lines (69 loc) · 1.89 KB

Readme.adoc

File metadata and controls

90 lines (69 loc) · 1.89 KB

.NET 8 — Minimal API Example

Example project for a minimal WebAPI with SQLite database backend. Contains all common tasks in a very condensed form.

Based on the following, simple data model:

@startuml
hide empty methods

enum ProductTypes {
    Food
    Drink
}
entity Product {
    Id: int
    Name: string
    Type: ProductTypes
    Price: decimal
    Hot: bool
    Vegetarian: bool
    Ingredients: List<Ingredient>
}
entity Menu {
    MenuNo: byte
    Date: DateOnly
    Products: List<MenuItem>
}
class Ingredient {
    Description: string
    Allergens: List<string>
}
entity MenuItem {
    Amount: short
}

ProductTypes "1" -r- "n" Product
Product "m" -r- "n" Menu
Product *-u- "n" Ingredient
(Product, Menu) .. MenuItem
@enduml

1. Create Database

If you want to create the SQLite database in your dev environment first make sure you have the EF tools installed (dotnet tool install --global dotnet-ef).

Then run dotnet ef database update to apply the migrations contained in the project.

Note
The application will (re)create the database automatically when started, so this step is only required if you want to inspect the sample data while the application is not running.

2. Running the Application

3. Publishing

For deployment to the server execute

dotnet publish -c Release -r linux-x64 --self-contained true
Note
If testing on Windows use RID win-x64

Allow the executable to be executed with:

chmod +x MinmalBackend

Then execute with

./MinmalBackend