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
91
Build Web APIs Faster with .NET Core Scaffolding
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
53
EF Core with Patterns
tonysneed
0
250
Follow Your IT Dreams
tonysneed
0
69
Dockerising ASP.NET Core Applications
tonysneed
1
130
Fun with Visual Studio Code
tonysneed
0
120
Other Decks in Technology
See All in Technology
それぞれのペースでやっていく Bet AI / Bet AI at Your Own Pace
yuyatakeyama
1
600
Hardware/Software Co-design: Motivations and reflections with respect to security
bcantrill
1
260
「全社導入」は結果。1人の熱狂が組織に伝播したmikanのn8n活用
sota_mikami
0
510
DEVCON 14 Report at AAMSX RU65: V9968, MSX0tab5, MSXDIY etc
mcd500
0
230
Amazon ElastiCacheのコスト最適化を考える/Elasticache Cost Optimization
quiver
0
140
新規事業 toitta におけるAI 機能評価の話 / AI Feature Evaluation in toitta
pokutuna
0
270
ファシリテーション勉強中 その場に何が求められるかを考えるようになるまで / 20260123 Naoki Takahashi
shift_evolve
PRO
3
380
Lambda Durable FunctionsでStep Functionsの代わりはできるのかを試してみた
smt7174
2
140
【NGK2026S】日本株のシステムトレードに入門してみた
kazuhitotakahashi
0
170
AI開発をスケールさせるデータ中心の仕組みづくり
kzykmyzw
0
170
Claude in Chromeで始める自律的フロントエンド開発
diggymo
1
270
なぜCREを8年間続けているのか / cre-camp-4-2026-01-21
missasan
0
1.3k
Featured
See All Featured
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
36k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
A designer walks into a library…
pauljervisheath
210
24k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
sira's awesome portfolio website redesign presentation
elsirapls
0
130
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
43
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.1k
The Invisible Side of Design
smashingmag
302
51k
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