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
Anthony Sneed
June 14, 2018
Technology
0
54
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
130
Fun with Visual Studio Code
tonysneed
0
120
Other Decks in Technology
See All in Technology
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
740
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
120
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
330
M&A 後の統合をどう進めるか ─ ナレッジワーク × Poetics が実践した組織とシステムの融合
kworkdev
PRO
1
490
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
390
Cloud Runでコロプラが挑む 生成AI×ゲーム『神魔狩りのツクヨミ』の裏側
colopl
0
130
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
200
Greatest Disaster Hits in Web Performance
guaca
0
280
20260204_Midosuji_Tech
takuyay0ne
1
160
広告の効果検証を題材にした因果推論の精度検証について
zozotech
PRO
0
210
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
SREチームをどう作り、どう育てるか ― Findy横断SREのマネジメント
rvirus0817
0
340
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
120
The agentic SEO stack - context over prompts
schlessera
0
650
Embracing the Ebb and Flow
colly
88
5k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
67
Mobile First: as difficult as doing things right
swwweet
225
10k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
420
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
79
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
190
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
290
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
58
50k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
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