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
client-side-Blazor で MVVM してみた
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ありとみ
July 30, 2019
Technology
500
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
client-side-Blazor で MVVM してみた
Blazor で 超単純な MVVM ハンズオン
ありとみ
July 30, 2019
Other Decks in Technology
See All in Technology
Tofu-Controller lightning talk @ Containerday 2026
gionn
0
110
JAWSUG TOHOKU 青森支部 「LoGoチャット」のAWS移行で 乗り越えたこと
taketakekaho
0
330
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
340
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
170
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
サブエージェントと Claude Mods で作る独自 Advisor ツールの話
kenichiodo
2
160
ソフトウェア ファクトリー - 再現性のあるソフトウェアの工場づくり / Software factory
iktakahiro
6
4.9k
JAWS-UGグッズ職人仕事の流儀
kentapapa
0
100
AI コーディングと人間の認知スループット / CTO Night & Day 2026 Morning Session / AI Coding and Human Cognitive Throughput
prog893
4
1k
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
4
1.1k
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
470
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
600
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
460
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
870
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3.1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
490
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
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
だけど、雰囲気良さそう