Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Build Web APIs Faster with .NET Core Scaffolding
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Anthony Sneed
June 14, 2018
Technology
0
55
Build Web APIs Faster with .NET Core Scaffolding
By Tony Sneed and Long Le
Anthony Sneed
June 14, 2018
Tweet
Share
More Decks by Anthony Sneed
See All by Anthony Sneed
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
92
EF Core with Patterns
tonysneed
0
260
Follow Your IT Dreams
tonysneed
0
72
Dockerising ASP.NET Core Applications
tonysneed
1
140
Fun with Visual Studio Code
tonysneed
0
130
Other Decks in Technology
See All in Technology
AWS SES VDMで 将来の配信事故を防げた話
moyashi
0
160
OCI Security サービス 概要
oracle4engineer
PRO
2
13k
聲の形にみるアクセシビリティ
tomokusaba
0
140
Abuse report だけじゃない。AWS から緊急連絡が来る状況とは?昨今の攻撃や被害の事例の紹介と備えておきたい考え方について
kazzpapa3
1
150
Dr. Werner Vogelsの14年のキーノートから紐解くエンジニアリング組織への処方箋@JAWS DAYS 2026
p0n
1
110
Serverless Agent Architecture on Azure / serverless-agent-on-azure
miyake
1
160
ヘルシーSRE
tk3fftk
2
240
us-east-1 に障害が起きた時に、 ap-northeast-1 にどんな影響があるか 説明できるようになろう!
miu_crescent
PRO
13
3.8k
わたしがセキュアにAWSを使えるわけないじゃん、ムリムリ!(※ムリじゃなかった!?)
cmusudakeisuke
1
400
Security Diaries of an Open Source IAM
ahus1
0
210
JAWS DAYS 2026 楽しく学ぼう!ストレージ 入門
yoshiki0705
2
110
タスク管理も1on1も、もう「管理」じゃない ― KiroとBedrock AgentCoreで変わった"判断の仕事"
yusukeshimizu
5
1.7k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
From π to Pie charts
rasagy
0
150
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Color Theory Basics | Prateek | Gurzu
gurzu
0
240
Deep Space Network (abreviated)
tonyrice
0
86
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Odyssey Design
rkendrick25
PRO
2
540
Between Models and Reality
mayunak
2
230
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
300
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
67
37k
エンジニアに許された特別な時間の終わり
watany
106
240k
Transcript
Build Web APIs Faster With .NET Core Scaffolding Tony Sneed
and Long Le
About Tony • Sr. Solutions Architect @ www.hilti.com • Coding
C# since v1 • Author / Instructor: DevelopMentor, Wintellect • Open Source: URF, Trackable Entities ASPNET Core, EF Core • blog.TonySneed.com • Twitter: @tonysneed
About Le • Sr. Solutions Architect @ www.hilti.com • Currently
geeking out with MEAN & .NET Core • Open Source: URF.Core, Trackable Entities • blog.longle.io • Twitter: @lelong37
Get the Slides Slides: https://speakerdeck.com/tonysneed/ build-web-apis-faster-with-net-core-scaffolding
Problem: Boilerplate code is time-consuming and boring!
Solution: .NET Core code scaffolding to the rescue!
Part 1: Intro to .NET Core Scaffolding
What is .NET Core Scaffolding? • Reverse engineer entity and
EF Core context classes from existing database • Create Web API controllers with CRUD operations based on EF Core context class
Scaffolding Approaches • Visual Studio wizards - EF Core Power
Tools - Add New Controller wizard - Visual Studio only - Windows only • Command line - .NET Core CLI - VS Code or Visual Studio - Cross-platform
EF Core: Not Your Father’s EF • Re-written from the
ground up! • .NET Standard 2.0 • Cross-Platform, Containers, Cloud Friendly • Modern, Modular, Extensible • Lightweight, Performant
Migrate from EF6 to Core? Don’t even think about it!
EF Core Power Tools • Reverse engineer • Visualize model
• Customize entity classes (Handlebars templates*) * Tony’s contrib :)
EF Core CLI • Cross Platform - Compatible with VS
Code on Windows or Mac • Flexible Options - Output entities and context to different projects
Project Structure • Entities: NET Standard 2.0 class library -
Compatible across all flavors of .NET • DbContext: .NET Core class library - EF Core CLI requires .NET Core • Web API: ASP.NET Core Project - Reference Entities and Data projects
Customizing Code Generation • Handlebars Templates - Double curly model
binding - Partial templates - Helper methods • IDesignTimeServices implementation - services.AddHandlebarsScaffolding • https://github.com/TrackableEntities/ EntityFrameworkCore.Scaffolding.Handlebars
Scaffolding Web API Controllers • Razor Templates - C# Syntax
- Partial templates - Helper methods • .NET Core CLI - dotnet new -i “AspNetCore.WebApi.Templates::*" • https://github.com/TrackableEntities/ AspNetCore.ApiControllers.Templates
None
Part 2: Design Patterns for EF Core
Why Patterns? • Using EF directly couples your app to
EF • Newing up DbContext makes your app less testable
Repository Pattern • Repository interfaces decouple app from persistence concerns
Sample Repository public class ProductRepository : IProductRepository { private readonly
NorthwindContext _dbContext; public ProductRepository(NorthwindContext dbContext) { _dbContext = dbContext; } public async Task<Product> FindAsync(int id) { return await _dbContext.Products.FindAsync(id); } }
Marking Changes public void Insert(Product product) { // Mark Added
_dbContext.Products.Add(product); } public void Update(Product product) { // Mark Modified _dbContext.Products.Update(product); } public async Task Delete(int id) { // Mark Deleted var product = await _dbContext.Products.FindAsync(id) _dbContext.Products.Remove(product); }
Unit of Work Pattern • Save changes from multiple repositories
• Wrapped in a single transaction
Persisting Changes public interface IUnitOfWork { Task<int> SaveChangesAsync(); }
Dependency Injection • DI container responsible for supplying instances •
DI is built into ASP.NET and EF Core
Helpful Frameworks • URF: Generic Unit of Work and Repository
https://github.com/urfnet/URF.Core
Helpful Frameworks • Trackable Entities: N-Tier Support for EF Core
https://github.com/TrackableEntities/ TrackableEntities.Core
None
Thank You! Tony Sneed: @tonysneed Long Le: @lelong37 Slides: https://speakerdeck.com/tonysneed/
build-web-apis-faster-with-net-core-scaffolding