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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
ありとみ
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
SREチームをどう作り、どう育てるか ― Findy横断SREのマネジメント
rvirus0817
0
320
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.6k
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
2
380
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
240
Greatest Disaster Hits in Web Performance
guaca
0
270
Context Engineeringの取り組み
nutslove
0
370
コスト削減から「セキュリティと利便性」を担うプラットフォームへ
sansantech
PRO
3
1.6k
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
250
Amazon S3 Vectorsを使って資格勉強用AIエージェントを構築してみた
usanchuu
3
450
30万人の同時アクセスに耐えたい!新サービスの盤石なリリースを支える負荷試験 / SRE Kaigi 2026
genda
4
1.3k
量子クラウドサービスの裏側 〜Deep Dive into OQTOPUS〜
oqtopus
0
130
ブロックテーマ、WordPress でウェブサイトをつくるということ / 2026.02.07 Gifu WordPress Meetup
torounit
0
190
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Speed Design
sergeychernyshev
33
1.5k
Designing Powerful Visuals for Engaging Learning
tmiket
0
240
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
320
What's in a price? How to price your products and services
michaelherold
247
13k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Side Projects
sachag
455
43k
Unsuck your backbone
ammeep
671
58k
The SEO identity crisis: Don't let AI make you average
varn
0
290
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
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
だけど、雰囲気良さそう