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
Minimal API と DI の良い組み合わせ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yuta Matsumura
November 28, 2022
Technology
3k
1
Share
Minimal API と DI の良い組み合わせ
.NET Conf Recap Fukuoka での登壇資料です。
https://msdevjp.connpass.com/event/264482/
Yuta Matsumura
November 28, 2022
More Decks by Yuta Matsumura
See All by Yuta Matsumura
エージェントスキルを作って自分のインプットに役立てよう v2
tsubakimoto_s
0
29
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
610
やさしいとこから始めるGitHubリポジトリのセキュリティ
tsubakimoto_s
3
2.4k
GitHub Copilot CLI で Azure Portal to Bicep
tsubakimoto_s
0
380
使って学ぼう MCP (と GitHub Codespaces)
tsubakimoto_s
1
300
GitHub Copilot CLI を使いやすくしよう
tsubakimoto_s
1
380
AspireとGitHub Modelsで作るお手軽AIアプリ
tsubakimoto_s
0
100
Memories of GitHub Universe & San Francisco
tsubakimoto_s
0
76
私のMCPの使い方
tsubakimoto_s
0
200
Other Decks in Technology
See All in Technology
アプリブロック機能のつくりかたと、AIとHTMLの不合理な相性の良さについて
kumamotone
1
260
Tachikawa.any 運営挨拶
daitasu
0
180
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.7k
PdM・Eng・QAで進めるAI駆動開発の現在地/aidd-with-pdm-eng-qa
shota_kusaba
0
250
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
4.5k
JTCでRedmine利用者2700人を実現した手法 第二部
nobuonakamura
0
120
マンション備え付けのネットワークとLTE回線を組み合わせた ネットワークの安定化の考案
harutiro
1
130
インプロセスQAのための要因から捉えるプロジェクトリスクマネジメントnano #1 開発リソース効率状態への対処 #jasstnano
barus_qa
0
140
可視化から活用へ — Mesh化・Segmentation・アライメントの研究動向
gpuunite_official
0
220
会社説明資料|株式会社ギークプラス ソフトウェア事業部
geekplus_tech
0
290
おいらのAWSアップデートの追い方〜Slack×AgentCore〜
yakumo
1
110
開発サイクルのボーダーレス化に伴う組織変革から学んだこと / Organizational Transformation Amid the Borderless Development Cycle
mii3king
0
160
Featured
See All Featured
Making the Leap to Tech Lead
cromwellryan
135
9.8k
Amusing Abliteration
ianozsvald
1
170
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
140
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
The SEO Collaboration Effect
kristinabergwall1
1
450
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
180
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
690
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
350
Transcript
#dotnetconf Minimal API と DI の良い組み合わせ 2022/11/25 .NET Conf Recap
Fukuoka Yuta Matsumura
#dotnetconf 松村 優大 (Yuta Matsumura) Chief Technical Architect (C#, PHP,
Azure) Microsoft MVP (Developer Technologies) #fukuten #devblogradio の中の人 @tsubakimoto_s Currently working for
#dotnetconf 本日お話しすること 1. ASP.NET Core Minimal API とは 2. これまでの
Web API 開発との違い 3. これから始める Minimal API 4. Minimal API x Dependency Injection 5. .NET 7 の Minimal API の新機能
#dotnetconf ASP.NET Core Minimal API とは • ASP.NET Core 6.0
で登場した機能 • 依存関係が最小限の Web API を作成 • ルーティングで構成するエンドポイント定義
#dotnetconf ASP.NET Core Minimal API とは • ASP.NET Core 6.0
で登場した機能 • 依存関係が最小限の Web API を作成 • ルーティングで構成するエンドポイント定義
#dotnetconf 最小限の依存関係 前提 (.NET 6.0 ~ / ASP.NET Core 6.0
~) 最小化されたホスティングモデル • Startup.cs が Program.cs に統合された • トップレベルステートメント • global using により using の記述量が減る
#dotnetconf #dotnetconf Program.cs
#dotnetconf #dotnetconf $ dotnet run info: Microsoft.Hosting.Lifetime[14] Now listening on:
http://localhost:5000 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Production info: Microsoft.Hosting.Lifetime[0] Content root path: C:¥Users¥yuta¥...¥MinimalConsole
#dotnetconf ルーティングで構成するエンドポイント定義 HTTP メソッド エンドポイント定義 HTTP GET MapGet HTTP POST
MapPost HTTP PUT MapPut HTTP DELETE MapDelete など https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/routing
#dotnetconf #dotnetconf Program.cs
#dotnetconf これまでの Web API 開発との違い • MVC の構成に合わせて実装する必要あり • Controller
クラス (ControllerBase クラス 要継承) • ApiController 属性 : API 用のコントローラーである目印 • Route 属性 : ルーティング構成 リソース数が増えると必要な Controller も増える https://learn.microsoft.com/en-us/aspnet/core/tutorials/min-web-api#differences-between-minimal-apis-and-apis-with-controllers
#dotnetconf これから始める Minimal API
#dotnetconf Swagger を構成しましょう .NET では Swashbuckle というライブラリを用いることで、 アプリケーションに Swagger を導入することができます。
https://github.com/domaindrivendev/Swashbuckle.AspNetCore
#dotnetconf ルーティングで構成するエンドポイント定義 HTTP メソッド エンドポイント定義 HTTP GET MapGet HTTP POST
MapPost HTTP PUT MapPut HTTP DELETE MapDelete など https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/routing
#dotnetconf #dotnetconf
#dotnetconf #dotnetconf Minimal API (Program.cs) DB (Usersテーブル) DbContext
#dotnetconf #dotnetconf データアクセスは 依存関係の解決 (DI) を介する
#dotnetconf #dotnetconf
#dotnetconf #dotnetconf ▼グルーピング可能
#dotnetconf #dotnetconf
#dotnetconf #dotnetconf
#dotnetconf #dotnetconf
#dotnetconf #dotnetconf パラメーターの取得元を 明示したい場合
#dotnetconf #dotnetconf API認証
#dotnetconf Minimal API x Dependency Injection
#dotnetconf “Fat Program.cs” 実際の API では様々なビジネスロジックが登場します。 しかし、これらを Program.cs に書くと複雑になります。 •
パラメーターのバリデーション • ログ出力 • データストアの CRUD • 他サービスとの連携 • HTTP レスポンスの構成
#dotnetconf Dependency Injection の活用 ビジネスロジック部分は専用のクラスで管理しましょう。 ※単一責任の原則 (SRP) ASP.NET Core では
Dependency Injection の仕組みがサポー トされているため、インターフェースで依存関係を構成する ことで、結果的に「テストしやすいAPI」となります。 https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/dependency-injection
#dotnetconf #dotnetconf ▶
#dotnetconf #dotnetconf
#dotnetconf .NET 7 の Minimal API の新機能 https://learn.microsoft.com/ja-jp/aspnet/core/release-notes/aspnetcore-7.0
#dotnetconf Rate Limit Middleware レート制限(時間内のリクエスト試行回数の制限)を ASP.NET Core 単体で構成することが可能となった。 レート制限に達した HTTP
リクエストに対しては HTTP 429 (Too Many Requests) のレスポンスを行う。
#dotnetconf Minimal API エンドポイントのフィルター エンドポイント前後で処理を 実行することが可能となった。
#dotnetconf 配列と文字列値のバインド ヘッダーやクエリ文字列に指定された値を配列にバインドす ることが可能となった。
#dotnetconf AsParametersAttribute 引数のバインドをクラスに置き換え可能となった。 ▼
#dotnetconf OpenAPI の機能強化 Microsoft.AspNetCore.OpenApi (nuget) を使用すると、 Minimal API のエンドポイントにて OpenAPI
定義を設定する ことが可能となった。
#dotnetconf ルートグループ リソース単位で API グルーピングする機能。 グループレベルで認証構成などが可能。
#dotnetconf おまけ 開発をラクにするちょっとしたツールたち
#dotnetconf dotnet-httprepl コマンドラインで使用する Web API クライアント。
#dotnetconf dotnet user-jwts 開発環境で使用する JWT (JSON Web Token) を発行するため のコマンドラインツール。
JWT に関する情報はユーザーシークレットに保管される。
#dotnetconf Appendix • .NET Conf での Minimal API セッション •
https://www.youtube.com/watch?v=uoVeZzKl6WQ (2021) • https://www.youtube.com/watch?v=HXHwtEjQoyM (2022) • Minimal API サンプルコード • https://github.com/tsubakimoto/dotnetconf-minimal-api-sample • https://github.com/captainsafia/TrainingApi • ドキュメント • https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/minimal-apis • https://learn.microsoft.com/ja-jp/aspnet/core/release-notes/aspnetcore-7.0 • https://learn.microsoft.com/ja-jp/aspnet/core/web-api/http-repl/ • https://learn.microsoft.com/ja-jp/aspnet/core/security/authentication/jwt-authn
#dotnetconf ご清聴ありがとうございました