Building Extensible RIAs with MEF

Preview:

DESCRIPTION

PDC 2009 Talk on building extensible Silverlight 4.0 applications using the new managed extensibility framework.

Citation preview

Building Extensible Rich Internet Applications with the Managed Extensibility FrameworkGlenn BlockProgram ManagerMicrosoft Corporation

What we’ll cover

RIA Extensions, add-ins, and plugins oh my!

Extensibility implants

Turning fat apps into slimmer apps

Reality

RIA 1.0

Reality

A

We need….

We need…..

BC

RIA 1.0

We need…..

D

EF

GH

IJ

K

We need…..We need…..

We need…..

We need…..

We need…..

We need…..

We need….

Managed Extensibility Framework

The Managed Extensibility Framework (MEF) is a new library in Silverlight 4 for building applications that can be incrementally extended.

> For customers> For you and your team > Always there, always ready

MEF Basics…An Application is built of

parts.

Hello MEF in Silverlight

Demo

MEF Basics…

Export it.

Import it.

Compose it.

Export it.

Widget1

[Export(typeof(UserControl))]public class Widget1 : UserControl{

public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Export

UserControl

Import it.

Widget1

[Export(typeof(UserControl))]public class Widget1 : UserControl{

[Import]public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Import

String

Import it.

Widget1

[Export(typeof(UserControl))]public class Widget1 : UserControl{

[Import(“HelloMEF.Message”)]public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Import

“HelloMEF.Message”

Import it.

MainPage

[Export(typeof(UserControl))]public class MainPage: UserControl{

[ImportMany(typeof(UserControl))]public IEnumerable<UserControl> { get;set;}

}

ImportMany

UserControl

Compose it.

PartIntializer: “Compose yourself”

MainPage Compose

public MainPage() { InitializeComponent(); PartInitializer.SatisfyImports(this); }

Be different – Use metadata

Widget

Widget

Where does the widget

go?

Export it - Metadata

Widget1

[ExportMetadata(“Location”,Location.Top)][Export(typeof(UserControl))]public class Widget1 : UserControl{

public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Export

UserControl

Put me in the top

Import it - Metadata

MainPage

[Export(typeof(UserControl))]public class MainPage: UserControl{

[ImportMany(typeof(UserControl))]public IEnumerable<Lazy<UserControl, IWidgetMetadata> { get;set;}

}

ImportMany

UserControl

Have it your way! – Custom Exports

Export it - Metadata

Widget1

[ExportMetadata(“Location”,Location.Top)][Export(typeof(UserControl))]public class Widget1 : UserControl{

public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Export

UserControl

Put me in the top

Customize it – Custom exports

Widget1

[Widget(Location=Location.Top)]public class Widget1 : UserControl{

public string Message { get{return(string) Button.Content;}

set{Button.Content=value;} }}

Export

UserControl

Put me in the top

Putting it all together

Demo

Trim up your appsbreak up your XAPs

Demo

MEF and Prism

Ariel Ben-Horesharielb@sela.co.ilblogs.microsoft.co.il/blogs/arielbh

DeveloperSela Group

partner

Introducing MEF-Prism integration

> Our Goal :

Enable an existing Prism application to be further extended through

MEF

> Enabled MEF modules to be added dynamically on the fly.

> Enable MEF discovered components to be registered in IoC container (Such as Unity).

Introducing MEF-Prism integration

> Prism application starts and loads up known modules.

Module Loader

Introducing MEF-Prism integration> Prism application can load unknown

plugins, by using MEF as an abstraction layer.

1. Plugins are located and added to a MEF catalog.

Server

Introducing MEF-Prism integration> Prism application can load unknown

plugins, by using MEF as an abstraction layer.

2. Plugins register dependencies with current IoC container.

Server

Introducing MEF-Prism integration> Prism application can load unknown

plugins, by using MEF as an abstraction layer.

3. Plugins are activated. Dependencies are injected.

Server

Where can I get it?

> MEF ships in Silverlight 4.0> Dynamic XAP support in SL 4.0 Toolkit> Silverlight 3.0 support on Codeplex> MEF source ships under MSPL

Learn more:Silverlight.netMEF.Codeplex.comMEFContrib.Codeplex.com – Prism/MEFblogs.msdn.com/gblock

MEF Cross-platform(s)

Jackson Harperjackson@novell.comblog.MonoOnTheWeb.info Software EngineerMoonlight Project

partner

© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.