When MEF meets Silverlight

Preview:

DESCRIPTION

Cairo Code Camp 2010

Citation preview

1

When MEF meets SilverlightAmr Elsehemy

amr.elsehemy@me.com

2

Speaker

• TA at Faculty of Information and Computer Science Ain Shams University

• Senior Software Engineer at ITWorx

• MCSD, MCPD + more.

3

What's MEF?

• The Managed Extensibility Framework– “The Managed Extensibility Framework (MEF)

is a new library in .NET 4 / Silverlight 4 for building applications that can be incrementally extended” – mef team

– “An extensible framework for composing applications from a set of loosely-couple parts discovered and evolving at run-time” – mtaulty

4

Why was MEF built?

App

Add B

Put the D

Can I have C

I need A

Then get me E

F

G

A

C

B

GD

EF

5

Why MEF

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

– In the framework!

6

MEF Basics…

An Application is built of parts

7

DemoBuilding our thing

8

3 Magic steps

• Export it

• Import it

• Compose it

9

Export it

[Export(typeof(IThing))]public class Thing{}

9

ExportIThing

10

Import it

public class MainPage{ [Import(typeof(IThing))] public IThing thing;}

10

IThing

Import

11

Compose it

11

public class MainPage{public MainPage(){

CompositionInitializer.SatisfyImports(this);}

Compose

12

DemoGiving more

13

Import it - Metadata

ImportMany

[ImportMany]public IEnumerable<Lazy<IThing,

IThingMetadata>> somethings;

IThing

14

Export it - Metadata

Put me in the

left

Export

[ExportMetadata("Position", ThingPosition.Left)][Export(typeof(IThing))]public partial class Thing{}

IThing

15

Customize it – Custom exports

[ThingExport(Position = ThingPosition.Left)] public class Thing{}

15

Put me in the

left

ExportIThing

16

DemoExploring the catalogs

17

AggregateCatalog

AssemblyCatalog

TypeCatalog

Compose it – Catalogs

18

DemoTrim your apps break up your xaps

19

Recomopose - DeploymentCatalog

• Recomposition is key in Silverlight apps– Initial download, small in size.– Download more functionality.

• A special Silverlight catalog DeploymentCatalog.

• Trace changes with IPartImportsSatisfiedNotification

21

MEF versions

• .NET Framework shipping with Silverlight4• .NET Framework 4 shipping with VS 2010• Silverlight 3 & .NET Framework V3.5 SP1

– Source on Codeplex (MSPL)

22

Resources

• silverlight.net• mef.codeplex.com• mefcontrib.codeplex.com• blogs.msdn.com/gblock• mtaulty.com – He is awesome!

– channel9.msdn.com/tags/learnMEFSL4

23

Questions?

24

Thank you

• Contacts amr.elsehemy@me.com twitter @amrelsehemy Blog

http://amrelsehemy.net