Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Build Web APIs Faster with .NET Core Scaffolding
Search
Anthony Sneed
June 14, 2018
Technology
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Build Web APIs Faster with .NET Core Scaffolding
Anthony Sneed
June 14, 2018
More Decks by Anthony Sneed
See All by Anthony Sneed
Build Web APIs Faster with .NET Core Scaffolding
tonysneed
0
73
EF Core with Patterns
tonysneed
0
280
Follow Your IT Dreams
tonysneed
0
84
Dockerising ASP.NET Core Applications
tonysneed
1
150
Fun with Visual Studio Code
tonysneed
0
140
Other Decks in Technology
See All in Technology
新卒エンジニア、 介護士になる
ryu1013
1
690
2026 Apache Flink Community Checkpoint
rmetzger
0
200
HQ駆動開発で最高のAI-Contextを作ろう
sansantech
PRO
1
110
Lint の層を組み直した話
bengo4com
3
330
Kiro Crew 入門 (手を離しても進む仕事) | 目指せ Kiro マスター 11
inariku
PRO
4
540
In-Context Learning再入門。ICLの勾配降下的解釈の研究動向を追ってみる。
dai08srhg
1
730
現場を動かすAIエージェント#2_製造業現場でのAI活用から見た、ハマる罠と実践知
kintotechdev
2
200
並列度を下げたら速くなった — go build の重複コンパイルを実測で見る
tomoaki25
2
880
公共システムAdventCalendar2026
toru_kubota
0
280
SLOを阻む不安
sraku2159
0
230
Technical Project Manager の役割とやりがい、少しだけ AI
yoshiiryo1
0
600
Shared Signals Framework 仕様解説
oidfj
0
220
Featured
See All Featured
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
Deep Space Network (abreviated)
tonyrice
0
410
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.6k
A designer walks into a library…
pauljervisheath
211
25k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.3k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
390
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Mind Mapping
helmedeiros
1
430
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
520
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
380
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
680
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
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/ef-core-with-patterns
Bits: https://github.com/tonysneed/Demo.EfCore.Patterns
Thank You! Tony Sneed: @tonysneed Long Le: @lelong37 Slides: https://speakerdeck.com/tonysneed/ef-core-with-patterns
Bits: https://github.com/tonysneed/Demo.EfCore.Patterns