23
When MEF meets Silverlight Amr Elsehemy [email protected] 1

When MEF meets Silverlight

Embed Size (px)

DESCRIPTION

Cairo Code Camp 2010

Citation preview

Page 1: When MEF meets Silverlight

1

When MEF meets SilverlightAmr Elsehemy

[email protected]

Page 2: When MEF meets Silverlight

2

Speaker

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

• Senior Software Engineer at ITWorx

• MCSD, MCPD + more.

Page 3: When MEF meets Silverlight

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

Page 4: When MEF meets Silverlight

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

Page 5: When MEF meets Silverlight

5

Why MEF

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

– In the framework!

Page 6: When MEF meets Silverlight

6

MEF Basics…

An Application is built of parts

Page 7: When MEF meets Silverlight

7

DemoBuilding our thing

Page 8: When MEF meets Silverlight

8

3 Magic steps

• Export it

• Import it

• Compose it

Page 9: When MEF meets Silverlight

9

Export it

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

9

ExportIThing

Page 10: When MEF meets Silverlight

10

Import it

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

10

IThing

Import

Page 11: When MEF meets Silverlight

11

Compose it

11

public class MainPage{public MainPage(){

CompositionInitializer.SatisfyImports(this);}

Compose

Page 12: When MEF meets Silverlight

12

DemoGiving more

Page 13: When MEF meets Silverlight

13

Import it - Metadata

ImportMany

[ImportMany]public IEnumerable<Lazy<IThing,

IThingMetadata>> somethings;

IThing

Page 14: When MEF meets Silverlight

14

Export it - Metadata

Put me in the

left

Export

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

IThing

Page 15: When MEF meets Silverlight

15

Customize it – Custom exports

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

15

Put me in the

left

ExportIThing

Page 16: When MEF meets Silverlight

16

DemoExploring the catalogs

Page 17: When MEF meets Silverlight

17

AggregateCatalog

AssemblyCatalog

TypeCatalog

Compose it – Catalogs

Page 18: When MEF meets Silverlight

18

DemoTrim your apps break up your xaps

Page 19: When MEF meets Silverlight

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

Page 20: When MEF meets Silverlight

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)

Page 21: When MEF meets Silverlight

22

Resources

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

– channel9.msdn.com/tags/learnMEFSL4

Page 22: When MEF meets Silverlight

23

Questions?

Page 23: When MEF meets Silverlight

24

Thank you

• Contacts [email protected] twitter @amrelsehemy Blog

http://amrelsehemy.net