a guided tour of mef in silverlight 4 mike taulty microsoft uk mtaulty@microsoft.com mtaulty.com...

Post on 02-Apr-2015

215 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

a guided tour of MEFin Silverlight 4

Mike Taulty

Microsoft UK

mtaulty@microsoft.com

mtaulty.com

@mtaulty

MEF – What is it? How and when do I get it?

• the Managed Extensibility Framework• an extensible framework for composing applications from a set of loosely-coupled parts discovered and evolving at run-time

• versions• .NET Framework shipping with Silverlight 4 • .NET Framework 4 shipping with VS 2010• CodePlex version for Silverlight 3, .NET 3.5 Sp1

IAlbumArtProvider

IAlbumInfoProvider

“scenario”

MediaPlayer

AlbumInfoProvider

AlbumArtProvider

GetAlbumInfo(“Blood on the Tracks”)

GetAlbumArt(“Blood on the Tracks”)

Constructor()

Constructor()

demousing MEF in our scenario

MEF models composable parts

Partexportexport

importimportimport

MEF composes parts

part

export

export

import

importimport

partimportimportimport

partexport

import

part

expo

rt

impo

rt

impo

rt

Composition Engine

Compose part

part

part

part

part

which parts compose together?

partexportexport

importimportimport

partimport

?Contract

Name

Cardinality

Shared

Recomposable

Metadata

Contract

Name

Shared

Metadata

demomatching imports to exports

parts & part definitions

•PartDefinition is a blueprint for a Part• similar to Object and Type in .NET• but can have Part without PartDefinition

Partexportexport

importimportimportPartDefinitio

n

export

import

CreatePart()

container draws parts from catalogs

CompositionContainer

Catalog

Catalog Catalog Catalog

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

PartDefinition

or mix in pre-instantiated parts

CompositionContainer

partExports(“Foo”)

Compose()

partImports(“Foo”)

demothe built-in catalogs*( *one is missing – we’ll come back to it later )

things change - recomposition

CompositionContainer

Catalog Catalog

PartDefinition

PartDefinition

PartDefinition

part

Compose()

partpart

PartDefinition

Some catalogs support additions

New parts [introduced to/removed from] container may have an impact on this import – a part can opt-in to allow this recomposition

part?

recomposition is key for Silverlight

MyApp.xap

initial, small download

Extras.xapadditional functionality

demorecomposition & the DeploymentCatalog( completing our story of built-in catalogs )

CompositionContainer

stable composition

reject parts with unsatisfied

imports

part

part

requires

requires

missing

reject changes that break “agreements”

part

part

requires exactlyone part

part

different part,same contract

demostable composition

MEF and Model View ViewModel• Strong separation of concerns possible with Silverlight development• user interface declared in XAML• loosely binds to data• functionality invoked by declarative commands

• Encapsulated by the “MVVM” pattern

model(“data”)

viewmodel(state & data for

view)

view(declarative XAML)

commands

binding

demoMEF and MVVM

Pointers to more advanced topics

extensibility – catalogs & export providers

CompositionContainer

ExportProvider

ExportProvider...CompositionContainer

ComposablePartCatalog

Catalog

ExportProvider

CatalogExportProvider

ExportProvider

AggregateExportProvider

ExportProvider

CatalogExportProvider

MEF Primitives

extensibility – programming models

• Programming models in MEF are pluggable

• [Attribute] is the built-in model

• Custom models involve implementing some/all of MEF’s primitive classes

ComposablePartCatalogComposablePartDefinition

ComposablePart

ExportDefinition

ImportDefinition

resources

•Channel 9 Silverlight 4 MEF Screencasts•channel9.msdn.com/tags/learnMEFSL4

•Glenn Block•blogs.msdn.com/gblock

•Nicholas Blumhardt•blogs.msdn.com/nblumhardt

•MEF on CodePlex•mef.codeplex.com

thanks for coming

feedback

top related