Monday, April 12, 2010

Implementation of PRISM in silvelight application.

PRISM or Composite Application guidance/Library


Prism or composite application guidance library helps us to build loosely coupled silver light or WPF applications.

It mainly contains
• Library
• Reference Implementation
• Documentation.

Prizm core concepts
 Container
 Bootstrapper
 Shell
 Modules
 Views
 Services

Unity Block:

 Dependency Injection Container
 Default for Prism (can use others though)
 Main functions:
 Register – Tell Unity it is responsible for a type or object
 Resolve – Obtain an object reference from the container
 BuildUp – Inject dependencies in an existing object
 Configure – Register based on configuration info
 Many overloads / variants
 Generic and non-generic versions

• Unit of the application assembly
• Unit of development
• Unit of deployment
Bootstrapper class is a main class to initialize.In this class shell object will be created as well as module is added to modulecatalog .
This class will be inherited by UnityBootstrapper class as shown in code snippet.

 Startup code for your application
 Alternative to putting everything in the Main() method
 Well defined intialization point in your application
 Not required, but recommended

public class BootStrapper:UnityBootstrapper
protected override DependencyObject CreateShell()
Shell arv_shl = Container.Resolve();
Application.Current.RootVisual = arv_shl;
return arv_shl;

protected override IModuleCatalog GetModuleCatalog()
ModuleCatalog modcatalog = new ModuleCatalog().AddModule(typeof(MainModule.Module));
return modcatalog;



Shell is exposing region of PRISM application.It is xaml file for rendering control.

 Main window of the application
 Could be more than one
 Presented at startup (typically, could be minimized to System
 Root element for the whole UI
 Even modular views that know nothing about the shell
 Typically knows nothing about the views that it is composed of
 Just provides a “shell” to contain them, thus the name
 May define regions for dynamic plug in of views
 May explicitly load views into containers in the UI

Output is rendered through the MainRegion(Items Control).

View and Modules

 Composite parts (Legos) of your UI
 Used to decompose your window from one big monolithic blob
into a bunch of semi-autonomous parts
 Can be defined as:
 User control
 Custom control
 WPF Data Template
 XAML Resource
 Dynamically constructed UI Element tree

View contains actual presentation xaml file, which contains all GUI. Module class is bridge between the view and bootstrapper class.

Code is as shown bellow.

public class Module:IModule
private readonly IRegionManager regionmanager;

public Module(IRegionManager regionManager)
regionmanager = regionManager;
public void Initialize()
regionmanager.RegisterViewWithRegion("MainRegion",typeof( TestModule));


Composit View:
 View that contains other views
 Child views may be added
 By composite view statically
 XAML declaration
 Programmatic addition
 Through regions within the composite view
 Composite view generally responsible for composing itself out of
child views
 May have some content of its own as well

This is the simplest silverlight-prism application!

No comments:

Post a Comment