- Create new empty ASP.NET 5 Web API CSharp9Demo
- With HTTPS
- With Docker
- Remove IIS Express launch settings
- Add analysis level preview for code quality
- Remove Startup.cs
- Replace Program.cs with Snippet 0010 Top-level Statements
- Try https://localhost:5001/health
Talk about top-level statements
- Add DummyAuthentication.cs with Snippet 0020 DummyAuthenticationHandler
- Add auth to DI with Snippet 0030 Authentication DI
- Add
app.UseAuthentication();andapp.UseAuthorization();afterUseRouting - Replace
MapGetwith Snippet 0040 Secure Health
Talk about attributes on local functions
- Try https://localhost:5001/health-secure
- Change role to SuperAdmin, try again -> forbidden
- Change role back
- Add Repository.cs
- Add base code with Snippet 0050 Repository Starter
- Add basic record with Snippet 0060 Person Record
- Add derived records with Snippet 0070 Derived Records
Talk about records in general (immutability)
- Add member to record
Personwith Snippet 0080 Record Member
Talk about the fact that records are just classes
- Add init-only property to record
Herowith Snippet 0090 Init-only Props
Talk about init-only properties
- Add base repository code with Snippet 0100 Base Repository
- Add initialization for heroes with Snippet 0110 Hero Initialize
Discuss advantages/disadvantages of target-typed
new
- Add LINQ query with relational pattern to record
HeroRepositorywith Snippet 0120 Relational Pattern
Talk about relational patterns
- Add
switchwith relational pattern toHerowith Snippet 0130 Switch with Relational Pattern - Add recursive relational pattern to
HeroRepositorywith Snippet 0140 Recursive Relational Pattern
- Create API Controller
HeroController - Add DTOs to
HeroControllerwith Snippet 0150 DTOs
Discuss attributes on init-only props
- Add
HeroRepositoryto DI:services.AddSingleton<HeroRepository>(); - Add repository to constructor for DI (
HeroRepository repository) - Add a method for getting all heroes with Snippet 0160 Get all heroes
Repeat pattern matching with records
- Add
AutoMapper.Extensions.Microsoft.DependencyInjectionNuGet package - Add AutoMapper to DI with Snippet 0170 Automapper setup
- Add method for getting all heroes (short version) with Snippet 0180 Get all heroes (short)
Discuss why AutoMapper just works (record = class)