SlideShare a Scribd company logo
1 of 47
Silverlight を使ったLarge-Scale Applicationの構築- MVVM及び Prism のご紹介 -  鈴木 章太郎 アーキテクトエバンジェリスト マイクロソフト株式会社 http://blogs.msdn.com/shosuz/  Twitter : @shosuz
アウトライン MVVM Model – View – ViewModel 何をするものか どこで使えば一番うまく使えるか 応用 Prism MVVMを有効に使うために ギャップを埋めるために オプション
ゴール Silverlight におけるMVVM の重要性 ゴールを達成するためには多くの手段がある 実際に動かしてみよう MVVM イネーブラについて学ぼう Prism 独自のものを作成しよう
他にも MV_ とついているものが…? MVVM MVC MVP MV???? アプリケーション構築において、メンテナンス性やスケーラビリティ確保のために、一般的に受け入れられているパターン
Model-View-ViewModel全体像MVVM, Prism, MEF - WCF RIA Services連携 WPF、Silverlight の疎結合 ソリューションのパターン 下記の実装を行う (トライアド) Model Data(Web)Service のエンティティ(をラップする) WCF RIA ServicesをModelと することも可能 ViewModel Modelを UI に合わせて公開する View ViewModelをXAML等でバインドする 参照:http://msdn.microsoft.com/ja-jp/magazine/dd458800.aspx
MVVMどんなものか?なぜ必要か? 関心の分離 View = UI を担当 Model = 純粋なデータを含む ViewModel = バインディングを通じたView と Model との間のコミュニケーション Silverlight と WPF とで有効活用可能 XAML ベースのデータバインディング テスト可能
MVVMどんなものか?なぜ必要か? Model :INotifyPropertyChanged、IDataErrorInfoを実装しているクラス (UI要素は持たず、Setter/Getterとしてのプロパティを持つのみ) ViewModelが取り扱うデータを保持するもの ViewModel:INotifyPropertyChangedを実装しているクラス (UI要素は持たず、ビジネスロジックやサーバーとの通信を担当する) 多くはObservableCollectionとしてViewにバインドするデータ(Model)を取得し、保持するもの 分離コードでCommandとイベントハンドラ(Command Receiver)の対応付けを行う Expression Blendのオブジェクトデータソースとしてスタティックリソース宣言が可能(ドラッグ&ドロップでUI構築)  View: XAMLによるUserControl (UI要素のみ) ViewModelから提供されるデータ(Model)を2-waysデータバインドにより表示・更新する XAML側でCommandの宣言を行う できれば分離コードを一切もたないdumbコントロールとしての実装が望ましい(ViewModelの割り当てをViewの分離コードで実行することもできるが、View –ViewModelの分離が不明確になる可能性がある)
The MVVM のトライアドすべてを一緒に View コントロールにデータを表示 UI フレンドリーなエンティティや、UI 状態、アクション データを表すエンティティ ViewModel Model
ModelMVVM データを表す エンティティ どこから取得したデータかは知る必要なし WCF サービス、WCF RIA Services 等々 バリデーションを含む場合あり
ViewMVVM 画面, UI, SilverlightのUserControl UI のルック&フィールを担当 情報を表示 バインディングを通じて、ViewModelとコミュニケート
ViewModelMVVM MVVM トライアドのためのロジックのメインソース Model をView と接続する Viewを抽象化する View にバインドされたPublic プロパティ INotifyPropertyChangedと、INotifyCollectionChangedとによる、バインディングを通じた View との会話 バインディングを通じたView からの変更の通知 MVVMトライアドの外部とのコミュニケートのためのサービスの呼び出し
MVVMはどこから始めるのが良いか?MVVM バリエーション View は ViewModelと何らかの関連性を持つ 幾つかの実施可能なオプション View First View Model First MVVM トライアドの個々のパーツのメンテナンス
View First MVVM Variations ViewModelは View の XAMLの中のスタティックなリソースとして宣言される Expression Blend で作れる もう一つの方法としては、ViewModelをView の分離コードで作成する
View First MVVM demo
ViewModel FirstMVVM バリエーション View は、ViewModelのコンストラクタにインジェクト(=注入)される Example: View がDependency Injection を使って作成されると、ViewModelが 作成される
View と ViewModelとの結び付けMVVM バリエーション View は ViewModelと何らかの形で一対になる ViewModelと View は一旦作成され、中間段階を経て、その後一対となる
View とViewModelとの結び付け vm = new MyVM(); view = new MyView(); view.DataContext = vm; // With Unity vm = container.Resolve<IMyVM>(); view = container.Resolve<MyView>(); view.DataContext = vm;
Prism についていつでも選択可能 Prism は、オプションのセット 使いたいものだけを選んで使い、残りは無視して良し 例 :  モジュールとコマンドは選ぶが、イベントアグリゲーションとリージョンは無視する Prism: patterns & practices Composite Application Guidance for WPF and Silverlight site http://www.codeplex.com/CompositeWPF
Prism の技術コンセプト Commands Shell Modules Bootstrapper Event Aggregation Container Regions Unity and DI
Bootstrapperスタートするための機能 アプリケーションを起動 メイン UI コンテナをスタート (Shell) (必要に応じて)モジュールの登録とロード グローバルシングルトンの登録 (オプション) 通常 “Bootstrapperプロジェクト” に含まれる
ShellメインView メイン UI コンテナ ロードされ得るすべての Viewをホスト リージョンに分割可能 Shell 自身は、その中に何がロードされるかを知らない
RegionsContent エリア View を配置できる Shell の中のエリア 名前を付ける必要あり コンテキストを内包可能 (オプション) RegionManagerによりRegionをメンテナンス可能
ModularitySelf Contained Modules ユーザーにとってはシームレス 分割して開発される 他のモジュールを参照してはならない Solution はModules に分割される Example: City government application Module 1: Managing land parcels Module 2: Traffic light administration Module 4: City Parks  Modules は、infrastructure と Models をシェアする
Dependency InjectionUnityの利用 Unity 又は他の DI ツール群 (例:Ninject) テスト可能でモック作成 抽象化 コンテナオブジェクトにより、クラスがそのインターフェースに従って登録される インターフェースをリクエストされたとき、コンテナは、当該インターフェースと一緒に登録されたクラスを、作成する シングルトンのサポート
クラスへのインターフェースの登録 container.RegisterType 	<IMyViewModel, MyViewModel>();
コンクリートClass の作成 container.Resolve<IMyViewModel>();
Infrastructure共通のTools Silverlight クラスライブラリプロジェクト モジュールのために共有可能なアイテムを含む Classes Assets Resources 何の参照も作成しない 純粋なライブラリ
Commandingアクションとリアクション データバインディングを通じた View とViewModelとの間のイベントを許可 ViewModelが宣言するのは Command receiver Command は XAMLの中で宣言される Button - Click ListBox (Selector) – Selected Command は、ViewModel の Command receiver にデータバインドされる ルールベースで disabled/enabled 設定可能
Commanding 実装のための5つのステップ – 前提 Silverlight 4 プロジェクトにおけるICommand実装は、数ステップで足りる 問い合わせの多い個所なので、下記にCommanding 実装のためのシンプルなテクニックを記述する
Commanding 実装のための5つのステップ – ICommandの実装 最初のステップは、ICommandインターフェースクラスの実装 このクラスはCommanding アスペクトを管理する 他にも色々オプションがあるところ、ここではシンプルなICommand の実装方法を紹介 当該 DelegatedCommandクラスで実装するのは、ICommandのCanExecuteメソッド、Execute メソッド、そして、CaneExecuteChangedイベント このコードはそのままコピー&ペーストして利用可能
Commanding 実装のための5つのステップ – ICommandの実装 ①  public class DelegateCommand : ICommand  { Func<object, bool> canExecute; 	Action<object> executeAction; boolcanExecuteCache; 	public DelegateCommand(Action<object>  executeAction, Func<object, bool>canExecute) 	{ this.executeAction= executeAction; this.canExecute= canExecute; 	} …
Commanding 実装のための5つのステップ – ICommandの実装 ② #region ICommandMembers 	public boolCanExecute(object parameter) 	{ booltemp = canExecute(parameter); 		if (canExecuteCache != temp) 		{ canExecuteCache= temp; 			if (CanExecuteChanged != null) 			{ CanExecuteChanged(this, new  EventArgs()); 			} 		} 		return canExecuteCache; 	}
Commanding 実装のための5つのステップ – ICommandの実装 ② ・・・続き・・・ 	public event EventHandlerCanExecuteChanged; 	public void Execute(object parameter) 	{ executeAction(parameter); 	} #endregion }
Commanding 実装のための5つのステップ – Commandの定義 //ICommand を表示するための Public プロパティ を ViewModelに追加 //このプロパティは 、通常は、ボタン等により、   View にバインドされる public ICommand LoadProductsCommand{ get; set; }
Commanding 実装のための5つのステップ – Command の作成 //ViewModelのコンストラクタの中で、  1で作成したコマンドプロパティを設定する LoadProductsCommand=   new DelegateCommand  (LoadProducts, CanLoadProducts);
Commanding 実装のための5つのステップ – ViewModelの作成 //ViewModelが View からアクセス可能なこと  を確認する // 様々な方法があるところ、シンプルに View  の XAML 中の Static Resource として作成 <UserControl.Resources> 	<local:ProductViewModel 									x:Key="vm"/> </UserControl.Resources>
Commanding 実装のための5つのステップ – Command のバインド //ボタンコントロールを追加し、当該コマンドプロパティを ViewModel の中で作ったコマンドにバインドする //当該Command に parameter を渡したい場合には、  CommandParameterプロパティを、当該 View の中の要素にバインド できる (通常は parameter は必要ないが、例として実装)  <Button  Content="Load" Width="120"  Command="{Binding LoadProductsCommand}" CommandParameter=  			"{Binding ElementName= FilterTextBox, Path=Text}"  />
Commanding 実装のための5つのステップ – ProductViewModel完成品 public class ProductViewModel : ViewModelBase {  public ProductViewModel() { this.Products= new ObservableCollection<Product>();  this.AllProducts= new ObservableCollection<Product>(); this.AllProducts.Add(new Product { ProductId = 1, ProductName = "Apple" }); this.AllProducts.Add(new Product { ProductId = 2, ProductName = "Orange" }); this.AllProducts.Add(new Product { ProductId = 3, ProductName = "Banana" });  this.AllProducts.Add(new Product { ProductId = 4, ProductName = "Pear" }) this.AllProducts.Add(new Product { ProductId = 5, ProductName = "Grape" });  this.AllProducts.Add(new Product { ProductId = 6, ProductName = "Grapefruit" }); this.AllProducts.Add(new Product { ProductId = 7, ProductName = "Strawberry" }) this.AllProducts.Add(new Product { ProductId = 8, ProductName = "Melon" }); this.AllProducts.Add(new Product { ProductId = 9, ProductName = "Guava" }); this.AllProducts.Add(new Product { ProductId = 10, ProductName = "Kiwi" }); this.AllProducts.Add(new Product { ProductId = 11, ProductName = "Pineapple" }); this.AllProducts.Add(new Product { ProductId = 12, ProductName = "Mango" }); LoadProductsCommand= new DelegateCommand(LoadProducts, CanLoadProducts);  	}  	private void LoadProducts(object param)  { 	string filter = param as string ?? string.Empty;  this.Products.Clear(); varquery = from p in this.AllProducts 	where p.ProductName.ToLower().StartsWith(filter.ToLower()) 	select p; foreach(var item in query) {  this.Products.Add(item); 	} }  	private boolCanLoadProducts(object param) {	return true }  	public ICommandLoadProductsCommand { get; set; }  public ObservableCollection<Product> AllProducts { get; set; }  private ObservableCollection<Product> products;  	public ObservableCollection<Product> Products {  		get 		{ 	 			return products 		} 		set 		{	products = value; this.FirePropertyChanged("Product"); 		}  }  }
Commanding 実装のための5つのステップ –ViewModel Base public abstract class ViewModelBase : INotifyPropertyChanged { public ViewModelBase() { } public event PropertyChangedEventHandlerPropertyChanged;  	protected void FirePropertyChanged(string propertyname)  { varhandler = PropertyChanged;  		if (handler != null)  				handler  (this, new PropertyChangedEventArgs(propertyname)); } }
Event Aggregatorパブリッシャとサブスクライバ 色々な種類のイベントをパブリッシュ及びサブスクライブ可能にする クロスモジュール化可能 サブスクライバによるフィルタリング可能 例えば: Shell の中のMenu アイテム上をクリック イベントはパブリッシャから呼び出される イベントはサブスクライバに受信される それにより、当該サブスクライバは、 Shell の中の、ある Region の中の、一つのViewをロードする
Infrastructure共通のTools Infrastructure は、Silverlight class library プロジェクト クラス、アセット、リソースを含み、モジュール間で共有される 他のモジュールを参照してはならない Web サービスをコールしてはならない 純粋なライブラリ
Modular MVVM and Prism demo
Screen Presentation EnablerScreensを生成する スクリーン間をナビゲート可能にしなければならない View 同志はお互いのことを知らない 独自のScreen Conductor を作成可能 Loading / Unloading Displaying / Hiding そのまま終了して良いですか? 自分でクリーンアップしましょう!
Screen Presentation FrameworkKey Players Screen MVVM トライアドを管理 ScreenFactory Screen class を作成 ScreenFactoryRegistry ScreenFactoryディレクトリ ScreenConductor Screen のアクティベーションイベントをリッスンしたり、その上で動いたりする ScreenCollection Screensを収集する
Screen Conductor demo
参考情報その他Blog、チュートリアル、サンプル、等々 Introducing the Earthquake Locator – A Bing Maps Silverlight Application, part 1  http://geekswithblogs.net/bdiaz/archive/2010/03/06/introducing-the-earthquake-locator--a-bing-maps-silverlight-application.aspx  MVVM Light Toolkit http://www.galasoft.ch/mvvm/getstarted/ Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 25: ViewModel http://blogs.msdn.com/brada/archive/2009/09/07/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-viewmodel.aspx ViewModel Pattern in Silverlight using Behaviors http://www.nikhilk.net/Silverlight-ViewModel-Pattern.aspx Simple Step for Commanding in Silverlight  http://devlicio.us/blogs/christopher_bennage/archive/2010/03/03/1-simple-step-for-commanding-in-silverlight.aspx
Building Silverlight Large Scale Application Using MVVM

More Related Content

Viewers also liked

Resources for PBL. The library : an essential partner. Author: Lorna Dodd
Resources for PBL. The library : an essential partner. Author: Lorna DoddResources for PBL. The library : an essential partner. Author: Lorna Dodd
Resources for PBL. The library : an essential partner. Author: Lorna DoddUCD Library
 
Using Social Networking Tools to Build Your Business
Using Social Networking Tools to Build Your BusinessUsing Social Networking Tools to Build Your Business
Using Social Networking Tools to Build Your BusinessTin Cans Unlimited
 
Solution semniar vs2013_multi_device-1209-new
Solution semniar vs2013_multi_device-1209-newSolution semniar vs2013_multi_device-1209-new
Solution semniar vs2013_multi_device-1209-newShotaro Suzuki
 
Lifenergy Web Marketing 2012
Lifenergy Web Marketing 2012Lifenergy Web Marketing 2012
Lifenergy Web Marketing 2012Lifenergy
 
Why the Grocery Business Must Go Social
Why the Grocery Business Must Go SocialWhy the Grocery Business Must Go Social
Why the Grocery Business Must Go SocialTribal DDB Vancouver
 
The librarian as lecturer : experiences on the other side of the fence. Autho...
The librarian as lecturer : experiences on the other side of the fence. Autho...The librarian as lecturer : experiences on the other side of the fence. Autho...
The librarian as lecturer : experiences on the other side of the fence. Autho...UCD Library
 
Teaching support : different perspectives, shared challenges. Authors: Ursula...
Teaching support : different perspectives, shared challenges. Authors: Ursula...Teaching support : different perspectives, shared challenges. Authors: Ursula...
Teaching support : different perspectives, shared challenges. Authors: Ursula...UCD Library
 
Vs2013 multi device shosuz
Vs2013 multi device shosuzVs2013 multi device shosuz
Vs2013 multi device shosuzShotaro Suzuki
 

Viewers also liked (20)

EDP Energias do Brasil Presentation
EDP Energias do Brasil PresentationEDP Energias do Brasil Presentation
EDP Energias do Brasil Presentation
 
Resources for PBL. The library : an essential partner. Author: Lorna Dodd
Resources for PBL. The library : an essential partner. Author: Lorna DoddResources for PBL. The library : an essential partner. Author: Lorna Dodd
Resources for PBL. The library : an essential partner. Author: Lorna Dodd
 
Using Social Networking Tools to Build Your Business
Using Social Networking Tools to Build Your BusinessUsing Social Networking Tools to Build Your Business
Using Social Networking Tools to Build Your Business
 
1Q06 Results
1Q06 Results1Q06 Results
1Q06 Results
 
Solution semniar vs2013_multi_device-1209-new
Solution semniar vs2013_multi_device-1209-newSolution semniar vs2013_multi_device-1209-new
Solution semniar vs2013_multi_device-1209-new
 
L'e-commerce in Italia - 2010
L'e-commerce in Italia - 2010L'e-commerce in Italia - 2010
L'e-commerce in Italia - 2010
 
Lifenergy Web Marketing 2012
Lifenergy Web Marketing 2012Lifenergy Web Marketing 2012
Lifenergy Web Marketing 2012
 
2007 Results
2007 Results2007 Results
2007 Results
 
Faces of italy profile italian
Faces of italy profile   italianFaces of italy profile   italian
Faces of italy profile italian
 
2Q05 Results
2Q05 Results2Q05 Results
2Q05 Results
 
Why the Grocery Business Must Go Social
Why the Grocery Business Must Go SocialWhy the Grocery Business Must Go Social
Why the Grocery Business Must Go Social
 
The librarian as lecturer : experiences on the other side of the fence. Autho...
The librarian as lecturer : experiences on the other side of the fence. Autho...The librarian as lecturer : experiences on the other side of the fence. Autho...
The librarian as lecturer : experiences on the other side of the fence. Autho...
 
3Q08 Results
3Q08 Results3Q08 Results
3Q08 Results
 
Processes: what should you measure?
Processes: what should you measure?Processes: what should you measure?
Processes: what should you measure?
 
Teaching support : different perspectives, shared challenges. Authors: Ursula...
Teaching support : different perspectives, shared challenges. Authors: Ursula...Teaching support : different perspectives, shared challenges. Authors: Ursula...
Teaching support : different perspectives, shared challenges. Authors: Ursula...
 
SLF grantmaking with Salesforce
SLF grantmaking with SalesforceSLF grantmaking with Salesforce
SLF grantmaking with Salesforce
 
Vs2013 multi device shosuz
Vs2013 multi device shosuzVs2013 multi device shosuz
Vs2013 multi device shosuz
 
Meeting With Investors and Analists
Meeting With Investors and AnalistsMeeting With Investors and Analists
Meeting With Investors and Analists
 
1Q09 Results
1Q09 Results1Q09 Results
1Q09 Results
 
SaIF Science Students - Success
SaIF  Science Students - SuccessSaIF  Science Students - Success
SaIF Science Students - Success
 

Similar to Building Silverlight Large Scale Application Using MVVM

PhoneGap勉強会 - 実践編 -
PhoneGap勉強会 - 実践編 -PhoneGap勉強会 - 実践編 -
PhoneGap勉強会 - 実践編 -Katsumi Onishi
 
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼう
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼうDELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼう
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼうKaz Aiso
 
ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~Yoshitaka Seo
 
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm pattern
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm patternRIAアーキテクチャー研究会 第3回 セッション4 Mvpvm pattern
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm patternMami Shiino
 
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT apps
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT appsMAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT apps
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT appsShotaro Suzuki
 
ASP.NET MVC と jQuery で実践する標準志向 Web 開発
ASP.NET MVC と jQuery で実践する標準志向 Web 開発ASP.NET MVC と jQuery で実践する標準志向 Web 開発
ASP.NET MVC と jQuery で実践する標準志向 Web 開発Akira Inoue
 
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよクライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよSeki Yousuke
 
Xamarin+MVVMCross のあれこれ
Xamarin+MVVMCross のあれこれXamarin+MVVMCross のあれこれ
Xamarin+MVVMCross のあれこれShinichiAoyagi
 
jQuery と MVC で実践する標準志向 Web 開発
jQuery と MVC で実践する標準志向 Web 開発jQuery と MVC で実践する標準志向 Web 開発
jQuery と MVC で実践する標準志向 Web 開発Akira Inoue
 
20091030cakephphandson 01
20091030cakephphandson 0120091030cakephphandson 01
20091030cakephphandson 01Yusuke Ando
 
エンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJSエンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJSAyumi Goto
 
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発tomotoshi
 
Android sdk manual_1.02
Android sdk manual_1.02Android sdk manual_1.02
Android sdk manual_1.02Tomohiro Kondo
 
Android sdk manual_1.02
Android sdk manual_1.02Android sdk manual_1.02
Android sdk manual_1.02Tomohiro Kondo
 
LabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideLabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideYusuke Tochigi
 
Laravel5を使って開発してみた
Laravel5を使って開発してみたLaravel5を使って開発してみた
Laravel5を使って開発してみたTakeo Noda
 

Similar to Building Silverlight Large Scale Application Using MVVM (20)

PhoneGap勉強会 - 実践編 -
PhoneGap勉強会 - 実践編 -PhoneGap勉強会 - 実践編 -
PhoneGap勉強会 - 実践編 -
 
Mvpvm pattern
Mvpvm patternMvpvm pattern
Mvpvm pattern
 
Vue入門
Vue入門Vue入門
Vue入門
 
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼう
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼうDELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼう
DELPHI BOOT CAMP / DELPHIでビジュアル開発に挑戦しよう ◆ DAY2: DELPHIでUI設計のポイントを学ぼう
 
ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~ASP.NET MVC 2 ~新機能の紹介~
ASP.NET MVC 2 ~新機能の紹介~
 
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm pattern
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm patternRIAアーキテクチャー研究会 第3回 セッション4 Mvpvm pattern
RIAアーキテクチャー研究会 第3回 セッション4 Mvpvm pattern
 
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT apps
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT appsMAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT apps
MAF2013 Enterprise Windows 8 – Architecture for rapid development of WinRT apps
 
ASP.NET MVC と jQuery で実践する標準志向 Web 開発
ASP.NET MVC と jQuery で実践する標準志向 Web 開発ASP.NET MVC と jQuery で実践する標準志向 Web 開発
ASP.NET MVC と jQuery で実践する標準志向 Web 開発
 
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよクライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
 
Xamarin+MVVMCross のあれこれ
Xamarin+MVVMCross のあれこれXamarin+MVVMCross のあれこれ
Xamarin+MVVMCross のあれこれ
 
jQuery と MVC で実践する標準志向 Web 開発
jQuery と MVC で実践する標準志向 Web 開発jQuery と MVC で実践する標準志向 Web 開発
jQuery と MVC で実践する標準志向 Web 開発
 
20091030cakephphandson 01
20091030cakephphandson 0120091030cakephphandson 01
20091030cakephphandson 01
 
PHP勉強会 #51
PHP勉強会 #51PHP勉強会 #51
PHP勉強会 #51
 
エンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJSエンタープライズ分野での実践AngularJS
エンタープライズ分野での実践AngularJS
 
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発
VSUGDAY2012 - ASP.NET MVC 4 Deveoper Preview による モバイルWEBアプリケーション開発
 
MVVM入門
MVVM入門MVVM入門
MVVM入門
 
Android sdk manual_1.02
Android sdk manual_1.02Android sdk manual_1.02
Android sdk manual_1.02
 
Android sdk manual_1.02
Android sdk manual_1.02Android sdk manual_1.02
Android sdk manual_1.02
 
LabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training SlideLabVIEW NXG Web Module Training Slide
LabVIEW NXG Web Module Training Slide
 
Laravel5を使って開発してみた
Laravel5を使って開発してみたLaravel5を使って開発してみた
Laravel5を使って開発してみた
 

More from Shotaro Suzuki

This is how our first offline technical event in three years was able to succ...
This is how our first offline technical event in three years was able to succ...This is how our first offline technical event in three years was able to succ...
This is how our first offline technical event in three years was able to succ...Shotaro Suzuki
 
Introducing the new features of the Elastic 8.6 release.pdf
Introducing the new features of the Elastic 8.6 release.pdfIntroducing the new features of the Elastic 8.6 release.pdf
Introducing the new features of the Elastic 8.6 release.pdfShotaro Suzuki
 
NET MAUI for .NET 7 for iOS, Android app development
 NET MAUI for .NET 7 for iOS, Android app development  NET MAUI for .NET 7 for iOS, Android app development
NET MAUI for .NET 7 for iOS, Android app development Shotaro Suzuki
 
What's New in the Elastic 8.5 Release
What's New in the Elastic 8.5 ReleaseWhat's New in the Elastic 8.5 Release
What's New in the Elastic 8.5 ReleaseShotaro Suzuki
 
Centralized Observability for the Azure Ecosystem
Centralized Observability for the Azure EcosystemCentralized Observability for the Azure Ecosystem
Centralized Observability for the Azure EcosystemShotaro Suzuki
 
What's New in the Elastic 8.4 Release
What's New in the Elastic 8.4 ReleaseWhat's New in the Elastic 8.4 Release
What's New in the Elastic 8.4 ReleaseShotaro Suzuki
 
Power Apps x .NET ~ Transforming Business Applications with Fusion Development
Power Apps x .NET ~ Transforming Business Applications with Fusion DevelopmentPower Apps x .NET ~ Transforming Business Applications with Fusion Development
Power Apps x .NET ~ Transforming Business Applications with Fusion DevelopmentShotaro Suzuki
 
devreljapan2022evaadvoc-final.pdf
devreljapan2022evaadvoc-final.pdfdevreljapan2022evaadvoc-final.pdf
devreljapan2022evaadvoc-final.pdfShotaro Suzuki
 
elastic-mabl-co-webinar-20220729
elastic-mabl-co-webinar-20220729elastic-mabl-co-webinar-20220729
elastic-mabl-co-webinar-20220729Shotaro Suzuki
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Shotaro Suzuki
 
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...Shotaro Suzuki
 
Building a search experience with Elastic – Introducing Elastic's latest samp...
Building a search experience with Elastic – Introducing Elastic's latest samp...Building a search experience with Elastic – Introducing Elastic's latest samp...
Building a search experience with Elastic – Introducing Elastic's latest samp...Shotaro Suzuki
 
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...Shotaro Suzuki
 
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...Shotaro Suzuki
 
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...Shotaro Suzuki
 
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -What's New in the Elastic 8.2 Release - Seamless User Experience with Search -
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -Shotaro Suzuki
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Shotaro Suzuki
 
Building Software Reliability through Distributed Tracing.pdf
Building Software Reliability through Distributed Tracing.pdfBuilding Software Reliability through Distributed Tracing.pdf
Building Software Reliability through Distributed Tracing.pdfShotaro Suzuki
 
Building a Flutter Development Environment with VSCode and Useful Extensions
Building a Flutter Development Environment with VSCode and Useful ExtensionsBuilding a Flutter Development Environment with VSCode and Useful Extensions
Building a Flutter Development Environment with VSCode and Useful ExtensionsShotaro Suzuki
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Shotaro Suzuki
 

More from Shotaro Suzuki (20)

This is how our first offline technical event in three years was able to succ...
This is how our first offline technical event in three years was able to succ...This is how our first offline technical event in three years was able to succ...
This is how our first offline technical event in three years was able to succ...
 
Introducing the new features of the Elastic 8.6 release.pdf
Introducing the new features of the Elastic 8.6 release.pdfIntroducing the new features of the Elastic 8.6 release.pdf
Introducing the new features of the Elastic 8.6 release.pdf
 
NET MAUI for .NET 7 for iOS, Android app development
 NET MAUI for .NET 7 for iOS, Android app development  NET MAUI for .NET 7 for iOS, Android app development
NET MAUI for .NET 7 for iOS, Android app development
 
What's New in the Elastic 8.5 Release
What's New in the Elastic 8.5 ReleaseWhat's New in the Elastic 8.5 Release
What's New in the Elastic 8.5 Release
 
Centralized Observability for the Azure Ecosystem
Centralized Observability for the Azure EcosystemCentralized Observability for the Azure Ecosystem
Centralized Observability for the Azure Ecosystem
 
What's New in the Elastic 8.4 Release
What's New in the Elastic 8.4 ReleaseWhat's New in the Elastic 8.4 Release
What's New in the Elastic 8.4 Release
 
Power Apps x .NET ~ Transforming Business Applications with Fusion Development
Power Apps x .NET ~ Transforming Business Applications with Fusion DevelopmentPower Apps x .NET ~ Transforming Business Applications with Fusion Development
Power Apps x .NET ~ Transforming Business Applications with Fusion Development
 
devreljapan2022evaadvoc-final.pdf
devreljapan2022evaadvoc-final.pdfdevreljapan2022evaadvoc-final.pdf
devreljapan2022evaadvoc-final.pdf
 
elastic-mabl-co-webinar-20220729
elastic-mabl-co-webinar-20220729elastic-mabl-co-webinar-20220729
elastic-mabl-co-webinar-20220729
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...
 
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...
Discover what's new in the Elastic 8.3 release - Find, monitor, and protect e...
 
Building a search experience with Elastic – Introducing Elastic's latest samp...
Building a search experience with Elastic – Introducing Elastic's latest samp...Building a search experience with Elastic – Introducing Elastic's latest samp...
Building a search experience with Elastic – Introducing Elastic's latest samp...
 
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...
Developing .NET 6 Blazor WebAssemby apps with Radzen Blazor component library...
 
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...
Elastic x Microsoft Azure Integration Evolution - Integrated Monitoring for S...
 
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...
Building 3D mobile apps using Power Apps Mixed Reality controls, Azure SQL Da...
 
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -What's New in the Elastic 8.2 Release - Seamless User Experience with Search -
What's New in the Elastic 8.2 Release - Seamless User Experience with Search -
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...
 
Building Software Reliability through Distributed Tracing.pdf
Building Software Reliability through Distributed Tracing.pdfBuilding Software Reliability through Distributed Tracing.pdf
Building Software Reliability through Distributed Tracing.pdf
 
Building a Flutter Development Environment with VSCode and Useful Extensions
Building a Flutter Development Environment with VSCode and Useful ExtensionsBuilding a Flutter Development Environment with VSCode and Useful Extensions
Building a Flutter Development Environment with VSCode and Useful Extensions
 
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...Application development with c#, .net 6, blazor web assembly, asp.net web api...
Application development with c#, .net 6, blazor web assembly, asp.net web api...
 

Recently uploaded

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案sugiuralab
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 

Recently uploaded (8)

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
TataPixel: 畳の異方性を利用した切り替え可能なディスプレイの提案
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 

Building Silverlight Large Scale Application Using MVVM

  • 1. Silverlight を使ったLarge-Scale Applicationの構築- MVVM及び Prism のご紹介 - 鈴木 章太郎 アーキテクトエバンジェリスト マイクロソフト株式会社 http://blogs.msdn.com/shosuz/ Twitter : @shosuz
  • 2. アウトライン MVVM Model – View – ViewModel 何をするものか どこで使えば一番うまく使えるか 応用 Prism MVVMを有効に使うために ギャップを埋めるために オプション
  • 3. ゴール Silverlight におけるMVVM の重要性 ゴールを達成するためには多くの手段がある 実際に動かしてみよう MVVM イネーブラについて学ぼう Prism 独自のものを作成しよう
  • 4. 他にも MV_ とついているものが…? MVVM MVC MVP MV???? アプリケーション構築において、メンテナンス性やスケーラビリティ確保のために、一般的に受け入れられているパターン
  • 5. Model-View-ViewModel全体像MVVM, Prism, MEF - WCF RIA Services連携 WPF、Silverlight の疎結合 ソリューションのパターン 下記の実装を行う (トライアド) Model Data(Web)Service のエンティティ(をラップする) WCF RIA ServicesをModelと することも可能 ViewModel Modelを UI に合わせて公開する View ViewModelをXAML等でバインドする 参照:http://msdn.microsoft.com/ja-jp/magazine/dd458800.aspx
  • 6. MVVMどんなものか?なぜ必要か? 関心の分離 View = UI を担当 Model = 純粋なデータを含む ViewModel = バインディングを通じたView と Model との間のコミュニケーション Silverlight と WPF とで有効活用可能 XAML ベースのデータバインディング テスト可能
  • 7. MVVMどんなものか?なぜ必要か? Model :INotifyPropertyChanged、IDataErrorInfoを実装しているクラス (UI要素は持たず、Setter/Getterとしてのプロパティを持つのみ) ViewModelが取り扱うデータを保持するもの ViewModel:INotifyPropertyChangedを実装しているクラス (UI要素は持たず、ビジネスロジックやサーバーとの通信を担当する) 多くはObservableCollectionとしてViewにバインドするデータ(Model)を取得し、保持するもの 分離コードでCommandとイベントハンドラ(Command Receiver)の対応付けを行う Expression Blendのオブジェクトデータソースとしてスタティックリソース宣言が可能(ドラッグ&ドロップでUI構築)  View: XAMLによるUserControl (UI要素のみ) ViewModelから提供されるデータ(Model)を2-waysデータバインドにより表示・更新する XAML側でCommandの宣言を行う できれば分離コードを一切もたないdumbコントロールとしての実装が望ましい(ViewModelの割り当てをViewの分離コードで実行することもできるが、View –ViewModelの分離が不明確になる可能性がある)
  • 8. The MVVM のトライアドすべてを一緒に View コントロールにデータを表示 UI フレンドリーなエンティティや、UI 状態、アクション データを表すエンティティ ViewModel Model
  • 9. ModelMVVM データを表す エンティティ どこから取得したデータかは知る必要なし WCF サービス、WCF RIA Services 等々 バリデーションを含む場合あり
  • 10. ViewMVVM 画面, UI, SilverlightのUserControl UI のルック&フィールを担当 情報を表示 バインディングを通じて、ViewModelとコミュニケート
  • 11. ViewModelMVVM MVVM トライアドのためのロジックのメインソース Model をView と接続する Viewを抽象化する View にバインドされたPublic プロパティ INotifyPropertyChangedと、INotifyCollectionChangedとによる、バインディングを通じた View との会話 バインディングを通じたView からの変更の通知 MVVMトライアドの外部とのコミュニケートのためのサービスの呼び出し
  • 12. MVVMはどこから始めるのが良いか?MVVM バリエーション View は ViewModelと何らかの関連性を持つ 幾つかの実施可能なオプション View First View Model First MVVM トライアドの個々のパーツのメンテナンス
  • 13. View First MVVM Variations ViewModelは View の XAMLの中のスタティックなリソースとして宣言される Expression Blend で作れる もう一つの方法としては、ViewModelをView の分離コードで作成する
  • 15. ViewModel FirstMVVM バリエーション View は、ViewModelのコンストラクタにインジェクト(=注入)される Example: View がDependency Injection を使って作成されると、ViewModelが 作成される
  • 16. View と ViewModelとの結び付けMVVM バリエーション View は ViewModelと何らかの形で一対になる ViewModelと View は一旦作成され、中間段階を経て、その後一対となる
  • 17. View とViewModelとの結び付け vm = new MyVM(); view = new MyView(); view.DataContext = vm; // With Unity vm = container.Resolve<IMyVM>(); view = container.Resolve<MyView>(); view.DataContext = vm;
  • 18. Prism についていつでも選択可能 Prism は、オプションのセット 使いたいものだけを選んで使い、残りは無視して良し 例 : モジュールとコマンドは選ぶが、イベントアグリゲーションとリージョンは無視する Prism: patterns & practices Composite Application Guidance for WPF and Silverlight site http://www.codeplex.com/CompositeWPF
  • 19. Prism の技術コンセプト Commands Shell Modules Bootstrapper Event Aggregation Container Regions Unity and DI
  • 20. Bootstrapperスタートするための機能 アプリケーションを起動 メイン UI コンテナをスタート (Shell) (必要に応じて)モジュールの登録とロード グローバルシングルトンの登録 (オプション) 通常 “Bootstrapperプロジェクト” に含まれる
  • 21. ShellメインView メイン UI コンテナ ロードされ得るすべての Viewをホスト リージョンに分割可能 Shell 自身は、その中に何がロードされるかを知らない
  • 22. RegionsContent エリア View を配置できる Shell の中のエリア 名前を付ける必要あり コンテキストを内包可能 (オプション) RegionManagerによりRegionをメンテナンス可能
  • 23. ModularitySelf Contained Modules ユーザーにとってはシームレス 分割して開発される 他のモジュールを参照してはならない Solution はModules に分割される Example: City government application Module 1: Managing land parcels Module 2: Traffic light administration Module 4: City Parks Modules は、infrastructure と Models をシェアする
  • 24. Dependency InjectionUnityの利用 Unity 又は他の DI ツール群 (例:Ninject) テスト可能でモック作成 抽象化 コンテナオブジェクトにより、クラスがそのインターフェースに従って登録される インターフェースをリクエストされたとき、コンテナは、当該インターフェースと一緒に登録されたクラスを、作成する シングルトンのサポート
  • 27. Infrastructure共通のTools Silverlight クラスライブラリプロジェクト モジュールのために共有可能なアイテムを含む Classes Assets Resources 何の参照も作成しない 純粋なライブラリ
  • 28. Commandingアクションとリアクション データバインディングを通じた View とViewModelとの間のイベントを許可 ViewModelが宣言するのは Command receiver Command は XAMLの中で宣言される Button - Click ListBox (Selector) – Selected Command は、ViewModel の Command receiver にデータバインドされる ルールベースで disabled/enabled 設定可能
  • 29. Commanding 実装のための5つのステップ – 前提 Silverlight 4 プロジェクトにおけるICommand実装は、数ステップで足りる 問い合わせの多い個所なので、下記にCommanding 実装のためのシンプルなテクニックを記述する
  • 30. Commanding 実装のための5つのステップ – ICommandの実装 最初のステップは、ICommandインターフェースクラスの実装 このクラスはCommanding アスペクトを管理する 他にも色々オプションがあるところ、ここではシンプルなICommand の実装方法を紹介 当該 DelegatedCommandクラスで実装するのは、ICommandのCanExecuteメソッド、Execute メソッド、そして、CaneExecuteChangedイベント このコードはそのままコピー&ペーストして利用可能
  • 31. Commanding 実装のための5つのステップ – ICommandの実装 ① public class DelegateCommand : ICommand { Func<object, bool> canExecute; Action<object> executeAction; boolcanExecuteCache; public DelegateCommand(Action<object> executeAction, Func<object, bool>canExecute) { this.executeAction= executeAction; this.canExecute= canExecute; } …
  • 32. Commanding 実装のための5つのステップ – ICommandの実装 ② #region ICommandMembers public boolCanExecute(object parameter) { booltemp = canExecute(parameter); if (canExecuteCache != temp) { canExecuteCache= temp; if (CanExecuteChanged != null) { CanExecuteChanged(this, new EventArgs()); } } return canExecuteCache; }
  • 33. Commanding 実装のための5つのステップ – ICommandの実装 ② ・・・続き・・・ public event EventHandlerCanExecuteChanged; public void Execute(object parameter) { executeAction(parameter); } #endregion }
  • 34. Commanding 実装のための5つのステップ – Commandの定義 //ICommand を表示するための Public プロパティ を ViewModelに追加 //このプロパティは 、通常は、ボタン等により、   View にバインドされる public ICommand LoadProductsCommand{ get; set; }
  • 35. Commanding 実装のための5つのステップ – Command の作成 //ViewModelのコンストラクタの中で、  1で作成したコマンドプロパティを設定する LoadProductsCommand=  new DelegateCommand  (LoadProducts, CanLoadProducts);
  • 36. Commanding 実装のための5つのステップ – ViewModelの作成 //ViewModelが View からアクセス可能なこと  を確認する // 様々な方法があるところ、シンプルに View の XAML 中の Static Resource として作成 <UserControl.Resources> <local:ProductViewModel x:Key="vm"/> </UserControl.Resources>
  • 37. Commanding 実装のための5つのステップ – Command のバインド //ボタンコントロールを追加し、当該コマンドプロパティを ViewModel の中で作ったコマンドにバインドする //当該Command に parameter を渡したい場合には、 CommandParameterプロパティを、当該 View の中の要素にバインド できる (通常は parameter は必要ないが、例として実装) <Button Content="Load" Width="120" Command="{Binding LoadProductsCommand}" CommandParameter= "{Binding ElementName= FilterTextBox, Path=Text}" />
  • 38. Commanding 実装のための5つのステップ – ProductViewModel完成品 public class ProductViewModel : ViewModelBase { public ProductViewModel() { this.Products= new ObservableCollection<Product>(); this.AllProducts= new ObservableCollection<Product>(); this.AllProducts.Add(new Product { ProductId = 1, ProductName = "Apple" }); this.AllProducts.Add(new Product { ProductId = 2, ProductName = "Orange" }); this.AllProducts.Add(new Product { ProductId = 3, ProductName = "Banana" }); this.AllProducts.Add(new Product { ProductId = 4, ProductName = "Pear" }) this.AllProducts.Add(new Product { ProductId = 5, ProductName = "Grape" }); this.AllProducts.Add(new Product { ProductId = 6, ProductName = "Grapefruit" }); this.AllProducts.Add(new Product { ProductId = 7, ProductName = "Strawberry" }) this.AllProducts.Add(new Product { ProductId = 8, ProductName = "Melon" }); this.AllProducts.Add(new Product { ProductId = 9, ProductName = "Guava" }); this.AllProducts.Add(new Product { ProductId = 10, ProductName = "Kiwi" }); this.AllProducts.Add(new Product { ProductId = 11, ProductName = "Pineapple" }); this.AllProducts.Add(new Product { ProductId = 12, ProductName = "Mango" }); LoadProductsCommand= new DelegateCommand(LoadProducts, CanLoadProducts); } private void LoadProducts(object param) { string filter = param as string ?? string.Empty; this.Products.Clear(); varquery = from p in this.AllProducts where p.ProductName.ToLower().StartsWith(filter.ToLower()) select p; foreach(var item in query) { this.Products.Add(item); } } private boolCanLoadProducts(object param) { return true } public ICommandLoadProductsCommand { get; set; } public ObservableCollection<Product> AllProducts { get; set; } private ObservableCollection<Product> products; public ObservableCollection<Product> Products { get { return products } set { products = value; this.FirePropertyChanged("Product"); } } }
  • 39. Commanding 実装のための5つのステップ –ViewModel Base public abstract class ViewModelBase : INotifyPropertyChanged { public ViewModelBase() { } public event PropertyChangedEventHandlerPropertyChanged; protected void FirePropertyChanged(string propertyname) { varhandler = PropertyChanged; if (handler != null) handler  (this, new PropertyChangedEventArgs(propertyname)); } }
  • 40. Event Aggregatorパブリッシャとサブスクライバ 色々な種類のイベントをパブリッシュ及びサブスクライブ可能にする クロスモジュール化可能 サブスクライバによるフィルタリング可能 例えば: Shell の中のMenu アイテム上をクリック イベントはパブリッシャから呼び出される イベントはサブスクライバに受信される それにより、当該サブスクライバは、 Shell の中の、ある Region の中の、一つのViewをロードする
  • 41. Infrastructure共通のTools Infrastructure は、Silverlight class library プロジェクト クラス、アセット、リソースを含み、モジュール間で共有される 他のモジュールを参照してはならない Web サービスをコールしてはならない 純粋なライブラリ
  • 42. Modular MVVM and Prism demo
  • 43. Screen Presentation EnablerScreensを生成する スクリーン間をナビゲート可能にしなければならない View 同志はお互いのことを知らない 独自のScreen Conductor を作成可能 Loading / Unloading Displaying / Hiding そのまま終了して良いですか? 自分でクリーンアップしましょう!
  • 44. Screen Presentation FrameworkKey Players Screen MVVM トライアドを管理 ScreenFactory Screen class を作成 ScreenFactoryRegistry ScreenFactoryディレクトリ ScreenConductor Screen のアクティベーションイベントをリッスンしたり、その上で動いたりする ScreenCollection Screensを収集する
  • 46. 参考情報その他Blog、チュートリアル、サンプル、等々 Introducing the Earthquake Locator – A Bing Maps Silverlight Application, part 1 http://geekswithblogs.net/bdiaz/archive/2010/03/06/introducing-the-earthquake-locator--a-bing-maps-silverlight-application.aspx  MVVM Light Toolkit http://www.galasoft.ch/mvvm/getstarted/ Business Apps Example for Silverlight 3 RTM and .NET RIA Services July Update: Part 25: ViewModel http://blogs.msdn.com/brada/archive/2009/09/07/business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update-viewmodel.aspx ViewModel Pattern in Silverlight using Behaviors http://www.nikhilk.net/Silverlight-ViewModel-Pattern.aspx Simple Step for Commanding in Silverlight http://devlicio.us/blogs/christopher_bennage/archive/2010/03/03/1-simple-step-for-commanding-in-silverlight.aspx

Editor's Notes

  1. 悩ましいのは、View上のいろんなイベント処理をいかに分離コード無しでコントロールするか、という点理想的にはViewはBehaviorを駆使して・・・、と行きたいところだが、業務系のシナリオを考えると難しい?スライド27 Commanding、28にあるEvent Aggregator、このあたりの明確な指針を出したい
  2. // Warning: DEMO CODE AHEAD // Your ViewModel should not define your data for your Model :-) // Instead, it could make a call to a service to get the data for the Model.
  3. // Warning: DEMO CODE AHEAD // Your ViewModel should not define your data for your Model :-) // Instead, it could make a call to a service to get the data for the Model.