bart j.f. de smet software development engineer microsoft corporation session code: dtl315

31

Upload: kelly-flynn

Post on 06-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

Agenda Why extensibility matters Extensibility the naïve way MEF versus System.Addin Core concepts Lots of demos Summary

TRANSCRIPT

Page 1: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315
Page 2: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Managed Extensibility FrameworkBart J.F. De [email protected]://blogs.bartdesmet.net/bartSoftware Development EngineerMicrosoft CorporationSession Code: DTL315

Page 3: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Agenda

Why extensibility mattersExtensibility the naïve wayMEF versus System.AddinCore conceptsLots of demosSummary

Page 4: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Extensibility in pictures

Source: http://www.gambiastart.nl

Page 5: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Customer versus developer

Source: http://www.insidefurniture.com Source: http://cristinalaird.files.wordpress.com

Page 6: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Extensibility is hard Looks familiar?

Too hard?

Page 7: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Take a step backinterface IMathBinOp{ string Name { get; } int Calculate(int a, int b);}

IMathBinOp GetOperation(string path, string type){ Assembly asm = Assembly.LoadFrom(path);

return (IMathBinOp)Activator.CreateInstance( asm.Name, type );}

Contract

Dynamic load

Name the 10 problems…

Page 8: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Extensibility the naïve wayBart J.F. De SmetSoftware Development EngineerMicrosoft Corporation

demo

Page 9: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Agenda

Why extensibility mattersExtensibility the naïve wayMEF versus System.AddinCore conceptsLots of demosSummary

Page 10: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Managed Extensibility Framework

Partshave a contract

are found in a catalog

compose in a container

Square with 4 pins

I have these blocks

Let’s build something

Page 11: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

System.Addin in a nutshellCross-

process or appdomain

Versioning adaptation

The essence of an add-in

Page 12: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Is System.Addin overkill?

System.AddinIsolation boundariesActivation of add-insAcross CLR versions

MEFComposition engine at its coreUtilities for discoverySimple declarative model

Answer: complimentary technologies

Page 13: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Agenda

Why extensibility mattersExtensibility the naïve wayMEF versus System.AddinCore conceptsLots of demosSummary

Page 14: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

A world of give and take

Import

Export

Composed

“I need” “I have”

Page 15: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Composition

Host application

Need a IMathBinOp

Extension A

Have a IMathBinOp

MEF composition

engine

[Export] [Import]

Part

Part

Page 16: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Import and Export in practiceinterface IMathBinOp{ string Name { get; } int Calculate(int a, int b);}

class Calculator{ [Import] public IMathBinOp Operator { get; set; }}

[Export(typeof(IMathBinOp))]class Add : IMathBinOp{ // Implementation}

Contract

Import

Export

Host applicationExtension

Page 17: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

How to compose?

CompositionContainerWiring “surface” where magic happens

CompositionBatchContains the parts to be wired together

ContainerBatch

PartCompose

Page 18: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Import and Export in practiceclass App{ static void Main() { var calc = new Calculator();

using (var container = new CompositionContainer()) { var batch = new CompositionBatch(); batch.AddPart(calc); batch.AddPart(new Add()); container.Compose(batch); }

var res = calc.Operator.Calculate(1,2); }}

Manual composition

Page 19: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Simple compositionBart J.F. De SmetSoftware Development EngineerMicrosoft Corporation

demo

Page 20: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Advanced topics in import/export

Named contractsTypically based on TypeCan also be string-based

ImportManyFor use with collectionsE.g. calculator has many operations

Instantiation controlWhich constructor to run?Part creation policies (sharing of instances)

Page 21: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Where do parts come from?

Concept of a catalogType catalog – explicit list of typesAssembly catalog – attributed types in an assemblyDirectory catalog – based on directory searchAggregate catalog – allows combining catalogs

Union operation

ComposablePartCatalog base classQueryable for parts (Parts)Search exports for a given import (GetExports)

Page 22: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Using a DirectoryCatalogclass App{ static void Main() { var calc = new Calculator();

var catalog = new DirectoryCatalog(EXTPATH); using (var container = new CompositionContainer(catalog)) { var batch = new CompositionBatch(); batch.AddPart(calc); container.Compose(batch); }

var res = calc.Operator.Calculate(1,2); }}

Search path

Page 23: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Working with catalogsBart J.F. De SmetSoftware Development EngineerMicrosoft Corporation

demo

Page 24: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Agenda

Why extensibility mattersExtensibility the naïve wayMEF versus System.AddinCore conceptsLots of demosSummary

Page 25: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Selection of MEF Preview 6 samplesBart J.F. De SmetSoftware Development EngineerMicrosoft Corporation

demo

http://mef.codeplex.com

Page 26: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Agenda

Why extensibility mattersExtensibility the naïve wayMEF versus System.AddinCore conceptsLots of demosSummary

Page 27: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

The ABC CCC of MEF

Extensibility

Compose

CatalogContract

Page 28: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

question & answer

Page 29: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

www.microsoft.com/teched

Sessions On-Demand & Community

http://microsoft.com/technet

Resources for IT Professionals

http://microsoft.com/msdn

Resources for Developers

www.microsoft.com/learning

Microsoft Certification & Training Resources

Resources

Page 30: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

Complete an evaluation on CommNet and enter to win!

Page 31: Bart J.F. De Smet  Software Development Engineer Microsoft Corporation Session Code: DTL315

© 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.