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
client-side-Blazor で MVVM してみた
Search
ありとみ
July 30, 2019
Technology
0
460
client-side-Blazor で MVVM してみた
Blazor で 超単純な MVVM ハンズオン
ありとみ
July 30, 2019
Tweet
Share
Other Decks in Technology
See All in Technology
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
240
[CV勉強会@関東 World Model 読み会] Orbis: Overcoming Challenges of Long-Horizon Prediction in Driving World Models (Mousakhan+, NeurIPS 2025)
abemii
0
140
We Built for Predictability; The Workloads Didn’t Care
stahnma
0
140
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
210
ランサムウェア対策としてのpnpm導入のススメ
ishikawa_satoru
0
210
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
700
Cosmos World Foundation Model Platform for Physical AI
takmin
0
950
量子クラウドサービスの裏側 〜Deep Dive into OQTOPUS〜
oqtopus
0
140
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
260
AI駆動開発を事業のコアに置く
tasukuonizawa
1
320
会社紹介資料 / Sansan Company Profile
sansan33
PRO
15
400k
ClickHouseはどのように大規模データを活用したAIエージェントを全社展開しているのか
mikimatsumoto
0
260
Featured
See All Featured
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
260
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
140
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
Chasing Engaging Ingredients in Design
codingconduct
0
110
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
110
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
Designing for humans not robots
tammielis
254
26k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
590
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
260
Docker and Python
trallard
47
3.7k
Scaling GitHub
holman
464
140k
Transcript
client-side-Blazor で MVVM してみた 株式会社スタディスト 有冨 隼
⾃⼰紹介 有冨 隼 / Shun Aritomi 株式会社スタディスト開発部 仕事内容 Windows アプリ開発
(WPF)
話すこと Blazor で 超単純な MVVM ハンズオン View への ViewModel を
DI する⽅法 View でコードビハインド使う⽅法 A simple MVVM implementation in client side Blazor. https://itnext.io/a-simple-mvvm- implementation-in-client-side-blazor- 8c875c365435
話さないこと Blazor の概要 MVVM の概要 MVVM における Model 部分の話
Blazor で MVVM しよう
準備 .NET Core 3.0 のインストール Visual Studio 2019 のインストール Visual
Studio の拡張機能 https://marketplace.visualstudio.com/items? itemName=aspnet.blazor
⽬次 View を作る ViewModelを作る BindableBase を作る ViewModel 本体を作る View と
ViewModel を紐付ける @inject を追加する DI コンテナへ登録する コードビハインド
View を作る input:2つ / output:1つ のシンプルな画⾯ Views/Sample.razor @page "/sample" <h1>Sample
Page</h1> <input /> + <input /> = <input readonly />
こんな⾒た⽬
ViewModel を作る (1) BindableBase クラスを作る INotifyPropertyChanged を実装 SetProperty` メソッドを実装 OnPropertyCanged
メソッドを実装 View <-> ViewModel 間の変更通知を実現する 不要でした
ViewModel を作る (2) BindableBase を継承したクラスを作る 継承不要でした
namespace WebApplication.ViewModels { public class SampleViewModel { public int Value1
{ get; set; } public int Value2 { get; set; } public int Result => Value1 + Value2; } }
View と ViewModel を紐付ける (1) View に @inject キーワードで DI
する input 項⽬は @bind キーワードに @ で値をセット output 項⽬は @ で値をセット @page "/sample" @using WebApplication.ViewModels @inject SampleViewModel ViewModel <h1>Sample Page</h1> <input @
[email protected]
/> + <input @
[email protected]
/> = <input readonly
[email protected]
/>
View と ViewModel を紐付ける (2) @inject で⾃動的に DI してもらうため DI
コンテナへの登録も必要 Startup.cs への追記 public void ConfigureServices(IServiceCollection services) { services.AddTransient<SampleViewModel>(); }
View に inject って書くの 嫌じゃない︖
View に inject って書くの 嫌じゃない︖ →実はコードビハインドで書ける
コードビハインド (1) [Viewファイル名].cs ファイルを作る (Views/Sample.razor.cs) View 側で @ で書いたキーワードは属性で記述する using
Microsoft.AspNetCore.Components; using WebApplication.ViewModels; namespace WebApplication.Views { public class SampleBase : ComponentBase { [Inject] public SampleViewModel ViewModel { get; set; } } }
コードビハインド (2) View へ @inherits キーワードで紐付ける @page "/samples" @inherits SampleBase
<h1>Sample Page</h1> <input @
[email protected]
/> + <input @
[email protected]
/> = <input readonly
[email protected]
/>
最終的にこんな感じになる デモ https://github.com/shuntaro4/SampleBlazor
まとめ Blazor でも MVVM できる Blazor でも コードビハインド的にかける まだ preview
だけど、雰囲気良さそう