Silverlight using prism v4
Download
1 / 44

Silverlight using Prism v4 - PowerPoint PPT Presentation


  • 329 Views
  • Uploaded on

Introduction to Architecting Silverlight Applications with Prism v4. Silverlight using Prism v4. Alan Cobb Independent .NET Consultant Sacramento, CA Silicon Valley Code Camp 2010 Sunday, October 10, 2010, 1:15pm (c) 2010 Alan Cobb, All rights reserved. About Alan Cobb.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Silverlight using Prism v4' - Samuel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Silverlight using prism v4 l.jpg

Introduction to Architecting SilverlightApplications with Prism v4

Silverlight using Prism v4

Alan Cobb

Independent .NET Consultant

Sacramento, CA

Silicon Valley Code Camp 2010

Sunday, October 10, 2010, 1:15pm

(c) 2010 Alan Cobb, All rights reserved.


About alan cobb l.jpg
About Alan Cobb

  • Independent consultant for over 20 years on Microsoft platforms

  • Silverlight, WPF, .NET, C#, C++

  • One of directors of the SacDotNet User Group

  • http://www.alancobb.com

  • http://www.alancobb.com/blog


Presentation overview l.jpg
Presentation Overview

  • Introduction:

    • What is common goal of Prism?

  • Prism features:

    • Dependency Injection: Unity / MEF

    • UI-Regions

    • Modularity

    • MVVM (Model-View-ViewModel)

    • Commanding, Loosely-coupled-events

  • Analyzing Prism code samples


Anti pattern big ball of mud l.jpg
Anti-pattern: Big Ball of Mud

Problems: Hard to see structure. Too many connections.


Anti pattern big ball of mud5 l.jpg
Anti-pattern: Big Ball of Mud

Problems: Hard to see structure. Too many connections


Overall prism goals l.jpg
Overall Prism Goals

  • Common goals behind Prism’s features:

    • Better ways to divide your app into parts

      • Modularity

      • UI-Regions

    • Better ways to find and connect the parts

      • Dependency-Injection (DI) with Unity or MEF

    • Better ways to communicate between parts

      • Commanding

      • Loosely coupled events


Goal clearer structure connections l.jpg
Goal: Clearer structure & connections

Benefits: Easier to understand, fix, extend and test.


Analogy to an optical prism l.jpg
Analogy to an optical prism

  • Prism helps break up an app into components. A little like a prism breaking up white light.




What do you get with prism l.jpg
What do you get with Prism?

  • Documentation (“guidance”)

  • Libraries with source code:

    • Prism

    • Unity or MEF (both optional)

    • Blend’s “Interactivity” assemblies

  • Samples

  • Discussion forum




Prism version history l.jpg
Prism version history

  • CAB: Composite Application UI Block

    • WinForms only – 2005

  • Prism v1 – 2008-06

    • WPF only

  • Prism v2.2 – 2010-06

  • Prism v4 – 2010-10

    • MEF introduced. MVVM support better.






Topic ui regions l.jpg
Topic: UI “Regions”

  • Sub-area of screen where views displayed

  • Like ASP.NET master pages

  • Decouples views from where they are shown or composed at a higher level



What is dependency injection di l.jpg
What is Dependency Injection (DI)?

  • Dependency Injection has similarities to a LAN


Topic dependency injection l.jpg
Topic: Dependency Injection

  • Dependency injection (DI) concepts

    • Containers

    • Registering and Resolving

    • Constructor and property injection

    • Lifetime management (singleton vs. instance)


Topic dependency injection23 l.jpg
Topic: Dependency Injection

  • Prism v4’s dependency injection choices:

    • Prismized-Unity

    • Prismized-MEF

      • MEF = Managed Extensibility Framework

      • Samples: “StockTrader RI”, “ModularityWithMef”

    • Native-MEF

      • Samples: “MVVM RI”

    • Other containers (StructureMap, etc.)

    • None






Di demo helloworld quickstart l.jpg
DI demo: HelloWorld Quickstart


Topic modularity l.jpg
Topic: Modularity

  • What is a Prism “module”?

    • Normally: One Project / Assembly / DLL

    • Possibly in separate XAP file

    • Initializing WhenAvailable or OnDemand

  • Using Prism modules:

    • Implementing IModule and IModule.Initialize()

    • ModuleCatalog in XAML or code.

    • StockTrader-RI no longer uses “modules”, just MEF.



Modularitywithmef sample details l.jpg
ModularityWithMef sample details

  • Using Fiddler to watch XAP downloads

  • MEF concepts in general:

    • Import, Export attributes and Contracts

    • Catalogs and Container

    • Compose, Recompose

  • MEF usage in sample:

    • [Import], [Export]

    • [ModuleExport]

    • IPartImportsSatisfiedNotification . OnImportsSatisfied


Topic mvvm l.jpg
Topic: MVVM

  • Model-View-ViewModel


Mvvm prism samples l.jpg
MVVM – Prism samples

  • Quickstart – BasicMVVM (will cover)

    • Only uses DelegateCommand from Prism

  • Quickstart – MVVM (will cover a bit)

    • No MEF/Unity or regions. Uses: Behaviors.

  • Quickstart – RegionNavigation (won’t cover)

  • MVVM RI (Reference Implementation)

    • Uses MVVM, native-MEF

  • StockTrader-RI

    • Uses MVVM, Prismized-MEF


  • Mvvm the main idea l.jpg
    MVVM: The main idea

    Benefits: Easier to understand, fix, extend and test.




    Mvvm quickstart details l.jpg
    MVVM Quickstart details

    • View’s DataContext set to ViewModel

    • NotificationObject (ViewModel base class)

    • VM can implement INotifyDataErrorInfo to support validation.

    • Uses “Behaviors” (behavior attached properties)

      • UpdateTextBindingOnPropertyChanged (Prism)

      • CallMethodAction (Blend. Calls method on VM.)

      • DataTrigger, EventTrigger and GoToStateAction (Blend. VM drives view to given VSM state.)


    Topic eventing l.jpg
    Topic: Eventing

    • Loosely-coupled events

    • Many-to-many, publish and subscribe

    • Communicate “loosely” between modules, between view-models.

    • Can use regular .NET events inside modules.

    • EventAggregator class (Singleton)

    • Alternative: Rx – Reactive Extensions




    Topic commanding l.jpg
    Topic: Commanding

    • Command types offered by Prism:

      • DelegateCommand

        • Implements ICommand.

      • CompositeCommand

    • Ways of using:

      • Local commands (View to ViewModel)

      • Global commands



    Topic multi targeting l.jpg
    Topic: Multi-targeting

    • Goal: Support both WPF and Silverlight

    • Goal: Share as much code as possible

    • Source file “Linking” within VS

    • Partial classes

    • #if #else conditional-compile blocks


    Alternatives to prism l.jpg
    Alternatives to Prism

    • MVVM-Light Toolkit

      • Supports MVVM, loose events and commands.

      • No DI (Unity, MEF) / modularity

      • No UI-Regions

      • Similar to Prism v4’s “MVVM RI” sample

    • Others

      • Caliburn, …

    • Roll-your-own