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
Minimal API と DI の良い組み合わせ
Search
Yuta Matsumura
November 28, 2022
Technology
3.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
ChatGPT製:GitHub Copilotの紹介(デモ)
tsubakimoto_s
1
38
MCPをつなげて作る組織横断のAIエージェント基盤(の開発工程)
tsubakimoto_s
0
250
Microsoft MVP プログラムを紹介するから目指す人増えてくれ
tsubakimoto_s
0
210
MCPをつなげて作る組織横断のAIエージェント基盤
tsubakimoto_s
0
880
github/awesome-copilotのPHPのエージェントスキルを読む
tsubakimoto_s
0
98
エージェントスキルを作って自分のインプットに役立てよう v2
tsubakimoto_s
0
71
エージェントスキルを作って自分のインプットに役立てよう
tsubakimoto_s
0
890
やさしいとこから始めるGitHubリポジトリのセキュリティ
tsubakimoto_s
4
2.6k
GitHub Copilot CLI で Azure Portal to Bicep
tsubakimoto_s
0
500
Other Decks in Technology
See All in Technology
人にやさしく、AIにやさしく、書き手を選ばないIaCのガードレール再考 / Rethinking IaC Guardrails for Humans and AI Alike
kohbis
5
1.6k
「ピッケル本」日本語版は4.0(第6版)が出版されるべき / pickaxe4-nagoyark05
kakutani
2
310
セルフサービスのオブザーバビリティ基盤をOpenTelemetryで作る / Building a Self-Service Observability Platform with OpenTelemetry
ymotongpoo
3
440
Amazon Bedrock Agents ClassicからAmazon Bedrock AgentCoreへ移行した際、ガードレール設定が2箇所に割れた話
matsunobu
0
150
なぜ「決定性」が 決定的に重要なのか? Durable Execution 基盤の数理的理解 #serverlessjp / ServerlessDays Tokyo 2026
ytaka23
4
1.3k
サーバーレスをどこまで使う? WebRTC対戦ゲームで選んだVPSとの共存設計
kaidouji85
0
490
認知負荷を吸収し、プロダクトをまたぐPR Preview基盤の設計事例
taiki45
2
520
Apache Iceberg が拓く AI 時代のオープンレイクハウス
tomtanaka
0
170
The kernel report
ennael
PRO
1
110
Azure Copilot Resiliency Agentをいろいろ試してみる
tomokusaba
0
130
音声コミュニティを守るAI監視基盤_ 90%以上の入力削減を支えたServerless設計と運用判断
shuheioka123
0
110
3人で1000GPU超を統合運用する?マルチクラウド&オンプレを跨ぐ、構築と運用のリアル!
kazukun0716
2
700
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
540
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
710
Navigating Weather and Climate Data
rabernat
0
540
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
330
sira's awesome portfolio website redesign presentation
elsirapls
0
430
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
Agile that works and the tools we love
rasmusluckow
331
22k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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 ご清聴ありがとうございました