MVVM Light ToolkitWorks Great, Less Complicated

29
MVVM Light Toolkit Works Great, Less Complicated Tom Fischer September 29, 2011

description

 

Transcript of MVVM Light ToolkitWorks Great, Less Complicated

Page 1: MVVM Light ToolkitWorks Great, Less Complicated

MVVM Light Toolkit Works Great, Less Complicated

Tom Fischer September 29, 2011

Page 2: MVVM Light ToolkitWorks Great, Less Complicated

∗ Background ∗ Enterprise Applications ∗ XAML ∗ Ramifications

∗ Architecture Considerations ∗ Patterns ∗ Toolkits

∗ Toolkit Demonstration ∗ Sample Application ∗ Incorporating MVVM Light

Agenda

Page 3: MVVM Light ToolkitWorks Great, Less Complicated

∗ Targets ∗ Any type of organization ∗ Any type of industry

∗ Not intended for consumers ∗ Function focused, such as, accounting, purchasing,

sales, etc.

Background: Enterprise Application Definition

Page 4: MVVM Light ToolkitWorks Great, Less Complicated

Background: Enterprise Application Sample

Page 5: MVVM Light ToolkitWorks Great, Less Complicated

Background: XAML Snippet

Page 6: MVVM Light ToolkitWorks Great, Less Complicated

∗ Declarative markup language for .NET API with XML nodes equating to CLR objects

∗ Features include ∗ Rich eventing support ∗ Declarative databinding ∗ Developer friendly conventions, such as, the content

property equals the “inner xml” of many nodes

Background: XAML Definition

Page 7: MVVM Light ToolkitWorks Great, Less Complicated

Background: XAML & CLR Objects

Page 8: MVVM Light ToolkitWorks Great, Less Complicated

∗ Enterprise applications do not ruthlessly follow well trodden UI guidelines; business users know what they want

∗ XAML does not mirror ASP.NET or Windows Form technologies, blindly adhering to their patterns & practices may result in harder to build and maintain Silverlight/WPF applications

Background: Ramifications

Page 9: MVVM Light ToolkitWorks Great, Less Complicated

Architecture Considerations: Options

∗ Patterns ∗ Code Behind ∗ MVC ∗ MVP ∗ MVVM

∗ Toolkits ∗ Caliburn Micro ∗ Catel ∗ MVVM Foundation ∗ MVVM Light Silverlight ∗ Simple MVVM ∗ Prism

Note: The above lists are NOT exhaustive.

Many other relevant patterns and toolkits exist.

Page 10: MVVM Light ToolkitWorks Great, Less Complicated

Architecture Considerations: The UI Pattern’s Pattern

Page 11: MVVM Light ToolkitWorks Great, Less Complicated

∗ Theoretical considerations ∗ Not the same as most software patterns (maybe why

some call them “frameworks”?) ∗ Technology dominates

∗ Practical considerations ∗ Application complexity and life span ∗ Development team’s abilities and interests ∗ Organizational resources and support

Architecture Considerations: UI Pattern Picking

Page 12: MVVM Light ToolkitWorks Great, Less Complicated

∗ MVC (Model-View-Controller) ∗ Conceived when viewers offered very little support for a

software developer writing presentation code ∗ Built with language and platform specific helpers

∗ MVP (Model-View-Presenter) ∗ 2nd generation MVC; facilitated testing ∗ Response to feature rich viewers

∗ MVVM (Model-View-ViewModel) ∗ 3rd generation MVC; reduced coder/designer friction ∗ Response to XAML

Architecture Considerations: UI Patterns and Technology

Page 13: MVVM Light ToolkitWorks Great, Less Complicated

∗ Plugs gap between technology and its use; maybe entitled “helper” code!?

∗ Considerations ∗ Fit (Simple as possible, but not simpler)

∗ How well does it plug the gap? ∗ Does it include more than required?

∗ Obsolescence susceptibility ∗ Handle newer, better technologies ∗ Ingest requirement/application changes

Architecture Considerations: Toolkit Overview

Page 14: MVVM Light ToolkitWorks Great, Less Complicated

∗ Overview ∗ Supports WPF and Silverlight ∗ Available on Microsoft Download Center

∗ V4 (11/2010) ∗ Supports MVVM many features, such as,

∗ Bootstrapper ∗ Dependency Injection (Unity & MEF) ∗ Composition (über) ∗ Event Aggregator ∗ Wiring Commands & Events

Architecture Considerations: Prism Toolkit

Page 15: MVVM Light ToolkitWorks Great, Less Complicated

Side Note: Prism It’s Complicated, Documented & Supported

Page 16: MVVM Light ToolkitWorks Great, Less Complicated

∗ Overview ∗ Supports WPF, Silverlight and Windows 7 ∗ Paired down version of Caliburn (10X smaller) ∗ Available on CodePlex

∗ V1.2 RTW (7/2011) ∗ 2,000+ downloads

∗ Supports MVVM and MVP with ∗ Bootstrapper ∗ Composition ∗ Event Aggregator ∗ Window Manager ∗ Wiring Commands & Events

Architecture Considerations: Caliburn Micro Toolkit

Page 17: MVVM Light ToolkitWorks Great, Less Complicated

∗ Overview ∗ Supports WPF, Silverlight and Windows 7 ∗ Available on CodePlex

∗ V3 SP1 (2/2011) ∗ 20,000+ downloads

∗ Supports MVVM with ∗ Event Aggregator ∗ Service Locator ∗ Wiring Commands & Events

Architecture Considerations: MVVM Light Toolkit

Page 18: MVVM Light ToolkitWorks Great, Less Complicated

∗ CSLA.NET ∗ Solves data access & business logic problems ∗ Works with most .NET UI technologies, especially those

leveraging databinding ∗ Not focused on specific UI pattern or technology

∗ Enterprise Library ∗ Addresses aspect oriented & generic problems ∗ Not associated with any UI pattern or technology

∗ Entity Framework ∗ Handles database exchanges ∗ Not associated with any UI pattern or technology

Side Note: What about CSLA.NET, Enterprise Library & Entity Framework?

Page 19: MVVM Light ToolkitWorks Great, Less Complicated

∗ MVVM pattern facilitates XAML-based enterprise applications ∗ Supports commands & databinding ∗ Minimizes designer-developer friction

∗ Many toolkits exist supporting MVVM-XAML ∗ Offer expected “helpers” ∗ Require varying degrees of “buy-in”

Architecture Considerations: Conclusion

Page 20: MVVM Light ToolkitWorks Great, Less Complicated

∗ Work thru a simple client information application with Silverlight (out of browser)

∗ Implement three iterations (as projects) ∗ 1st Iteration constructed as a basic non-MVVM ∗ 2nd Iteration converted to an MVVM to help handle

additional requirements ∗ 3rd Iteration incorporate MVVM Light to fix a few

architecture issues uncovered in 2nd Iteration

Toolkit Demonstration: Overview

Page 21: MVVM Light ToolkitWorks Great, Less Complicated

Toolkit Demonstration: Solution

1st Iteration

3rd Iteration

2ND Iteration

Page 22: MVVM Light ToolkitWorks Great, Less Complicated

∗ Solves known issues ∗ Communications between controls ∗ Turning UI events into commands

∗ Avoids unnecessary features (for now), e.g., ∗ Composition ∗ Navigation

∗ Reasonably documented and stable

Toolkit Demonstration: Why MVVM Light Toolkit?

Page 23: MVVM Light ToolkitWorks Great, Less Complicated

∗ MainPage.xaml.cs communicates with two models (ClientInformation and ClientPreferences)

∗ Databinding not employed; properties programmatically manipulated

Toolkit Demonstration: Sample Application 1st Iteration

Page 24: MVVM Light ToolkitWorks Great, Less Complicated

Toolkit Demonstration: Sample Application Models

2nd & 3rd Iteration

Page 25: MVVM Light ToolkitWorks Great, Less Complicated

∗ MainPage.xaml.cs indirectly communicates with three models (ClientInformation, ClientPreferences and ClientSale) via two ViewModel classes

∗ Databinding employed; UI events initiate data access

Toolkit Demonstration: Sample Application 2nd Iteration

Page 26: MVVM Light ToolkitWorks Great, Less Complicated

∗ 2nd iteration + MVVM Light Toolkit ∗ Databinding and commands leveraged to allow all logic to

live within the ViewModels

Toolkit Demonstration: Sample Application 3rd Iteration

Page 27: MVVM Light ToolkitWorks Great, Less Complicated

∗ 1st Iteration – architecture typical of many Windows Form-based applications

∗ 2nd Iteration – MVVM pattern applied with a few resulting “programming holes” ∗ Communications limited between controls ∗ Events to commands not fully supported

∗ 3rd Iteration – MVVM Light Toolkit addresses shortcomings from the 2nd Iteration

Toolkit Demonstration: Recap

Page 28: MVVM Light ToolkitWorks Great, Less Complicated

∗ Ability to dynamically load appropriate ViewModel classes (ServiceLocation)

∗ Designed to work well with Blend ∗ Developer Candy ∗ NuGet support ∗ Visual Studio templates ∗ C# snippets

Toolkit Demonstration: Some Other MVVM Light Features…

Page 29: MVVM Light ToolkitWorks Great, Less Complicated

∗Thanks for attending! ∗Any other questions?