$30 off During Our Annual Pro Sale. View Details »
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
SREが取り組むデプロイ高速化 ─ Docker Buildを最適化した話
capytan
0
140
AWS re:Invent 2025~初参加の成果と学び~
kubomasataka
0
190
Strands AgentsとNova 2 SonicでS2Sを実践してみた
yama3133
1
1.9k
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
2.4k
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.9k
AgentCoreとStrandsで社内d払いナレッジボットを作った話
motojimayu
1
950
_第4回__AIxIoTビジネス共創ラボ紹介資料_20251203.pdf
iotcomjpadmin
0
130
オープンソースKeycloakのMCP認可サーバの仕様の対応状況 / 20251219 OpenID BizDay #18 LT Keycloak
oidfj
0
170
AWS運用を効率化する!AWS Organizationsを軸にした一元管理の実践/nikkei-tech-talk-202512
nikkei_engineer_recruiting
0
170
AWSインフルエンサーへの道 / load of AWS Influencer
whisaiyo
0
220
日本の AI 開発と世界の潮流 / GenAI Development in Japan
hariby
1
450
ペアーズにおけるAIエージェント 基盤とText to SQLツールの紹介
hisamouna
2
1.7k
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
260
Visualization
eitanlees
150
16k
Design in an AI World
tapps
0
100
Testing 201, or: Great Expectations
jmmastey
46
7.8k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.1k
We Are The Robots
honzajavorek
0
120
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
410
KATA
mclloyd
PRO
33
15k
Crafting Experiences
bethany
0
22
Producing Creativity
orderedlist
PRO
348
40k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
89
Making the Leap to Tech Lead
cromwellryan
135
9.7k
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
だけど、雰囲気良さそう