0:00 Introduction
1:05 Terrible Client Example
2:45 Making a New API Project with Dotnet CLI
5:47 Our Most Minimal of Minimal APIs
7:49 Adding EF Core NuGet Packages
9:35 Starting To Set Up Our Models
14:00 Creating DbContext
21:00 Creating Our First Migration
28:50 Our First POST Endpoint
36:30 Get User By Id
43:02 Creating the Project Table
54:39 Configuring OnModelCreating
1:01 POST Endpoint For Creating a Project
1:04:40 Fake DTOs with JSON Ignore Attribute
1:06:42 Creating a Project with Invoke-RestMethod
1:08:58 The Ticket model
1:15:18 Configuring the Ticket Model with the Fluent API
1:24:37 POST Endpoint For Creating a Ticket
1:27:10 InverseProperty DataAnnotation
1:30:23 Creating a Ticket with Invoke-RestMethod
This video shows you how to create a backend skeleton of a simple project management app. We will create an API in .NET 6 with three tables: Users, Projects, and Tickets (i.e. Tasks).
Projects are categories for our tasks. A project could be something like "Make YouTube Videos." Making this specific video, the one you see right here, could be a "Ticket". The Project table has a one-to-many relationship with Tickets. (Each project can have many tickets. In a sense, a ticket is a sub-category of a project).
The project and ticket tables also have a relationship with the User table.
Projects keep track of what specific user created them (one-to-many). Tickets have two relationships with Users:
1.) Which specific user created the ticket
2.) Which specific user the ticket is currently assigned to
Later, if we add authentication or user roles, we can store the user role (Admin, Standard, etc.) inside the user table we create today. If we make our own sketchy, quasi-secure JWT authentication (not in this video) we can simply add that to our User table.
In fact, with just these three tables we can eventually build quite a complex project management app.
Next, we will configure our table relationships both with DataAnnotations and with the Fluent API.
The Fluent API, will allow us to configure relationships using the Has/With pattern. We can also specify the foreign key directly in OnModelCreating using the FluentAPI.
The FluentAPI allows us more options than just DataAnnotations alone. For example, "composite keys" are not possible only with DataAnnotations.
Instead of doing this the right way -- using Data Transfer Options and DTOs -- we are going to use the "JsonIgnore" attribute to make our models more JSON friendly.
.NET 6 Minimal API
We are going to delete all the boilerplate code and start from a blank file. We will add the bare minimum code needed to build our app and make an API in .NET.
We will show off how easy it is to make routes in .NET minimal APIs using
app.MapGet
Then I will become consumed with regret for not making a proper API with a Controllers folder and a real controller with real IActionResult objects. We will long for our proper ASP.NET controller attributes and advanced configuration.
I will be pretentious and only use VS Code and Windows Terminal - instead of using Visual Studio like a proper C# developer.
You will watch me using PowerShell's Invoke-RestMethod, for some reason, instead of using the amazing Swagger API. After the agony of testing our API only from the PowerShell terminal - when we finally use Swagger, in the next video, it will feel AMAZING!!!!!
LukeBug
Finally, we will briefly look at my terrible, terrible, terrible Blazor app (in development). You may die of laughter.
I will discuss my regrets in using Blazor Web Assembly (Blazor WASM) with its horrific loading time, instead of Angular.js. This poor choice is clearly part of a pattern of other poor life choices.
Tools used:
1. .NET 6 (dotnet.microsoft.com/en-us/download/dotnet/6.0)
2. Windows Terminal (www.microsoft.com/en-us/p/windows-terminal/)
3. PowerShell (docs.microsoft.com/en-us/powershell/scripting/inst…)
4. DB Browser for SQLite ( sqlitebrowser.org/)
5. VS Code (code.visualstudio.com/download)
VS Code Extensions:
1. OmniSharp (marketplace.visualstudio.com/items?itemName=ms-dot…)
2. SynthWave `84 (marketplace.visualstudio.com/items?itemName=RobbOw…)
3. VIM extension (marketplace.visualstudio.com/items?itemName=vscode…)
Other Tools:
1. Screencast-O-Matic (screencast-o-matic.com/)
2. Old Condensor microphone
2. Green screen my brother-in-law gave me
Feel free to email me at lavedon@gmail.com
LinkedIn: www.linkedin.com/in/lukeavedon/
Thanks for watching!! (and reading)
コメント