Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Bart J.F. De Smet Software Development Engineer Microsoft Corporation Session Code: DTL315."— Presentation transcript:

1

2 Bart J.F. De Smet bartde@microsoft.com http://blogs.bartdesmet.net/bart Software Development Engineer Microsoft Corporation Session Code: DTL315

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

4 Extensibility in pictures Source: http://www.gambiastart.nlhttp://www.gambiastart.nl

5 Customer versus developer Source: http://www.insidefurniture.comhttp://www.insidefurniture.com Source: http://cristinalaird.files.wordpress.comhttp://cristinalaird.files.wordpress.com

6 Extensibility is hard Looks familiar? Too hard?

7 Take a step back interface 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 ); } ContractContract Dynamic load Name the 10 problems…

8 Extensibility the naïve way Bart J.F. De Smet Software Development Engineer Microsoft Corporation

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

10 Managed Extensibility Framework Parts have a contract are found in a catalog compose in a container Square with 4 pins I have these blocks Let’s build something

11 System.Addin in a nutshell Cross- process or appdomain Versioning adaptation The essence of an add-in

12 Is System.Addin overkill? System.Addin Isolation boundaries Activation of add-ins Across CLR versions MEF Composition engine at its core Utilities for discovery Simple declarative model Answer: complimentary technologies

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

14 A world of give and take ImportExport Composed “I need” “I have”

15 Composition Host application Need a IMathBinOp Extension A Have a IMathBinOp MEF composition engine [Export][Export] [Import][Import] PartPart PartPart

16 Import and Export in practice interface 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 } ContractContract ImportImport ExportExport Host application Extension

17 How to compose? CompositionContainer Wiring “surface” where magic happens CompositionBatch Contains the parts to be wired together ContainerContainer BatchBatch PartPart Compose

18 Import and Export in practice class 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

19 Simple composition Bart J.F. De Smet Software Development Engineer Microsoft Corporation

20 Advanced topics in import/export Named contracts Typically based on Type Can also be string-based ImportMany For use with collections E.g. calculator has many operations Instantiation control Which constructor to run? Part creation policies (sharing of instances)

21 Where do parts come from? Concept of a catalog Type catalog – explicit list of types Assembly catalog – attributed types in an assembly Directory catalog – based on directory search Aggregate catalog – allows combining catalogs Union operation ComposablePartCatalog base class Queryable for parts ( Parts ) Search exports for a given import ( GetExports )

22 Using a DirectoryCatalog class 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

23 Working with catalogs Bart J.F. De Smet Software Development Engineer Microsoft Corporation

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

25 Selection of MEF Preview 6 samples Bart J.F. De Smet Software Development Engineer Microsoft Corporation http://mef.codeplex.com

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

27 The ABC CCC of MEF Extensibility ComposeCatalogContract

28

29 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

30 Related Content Breakout Sessions (session codes and titles) Interactive Theater Sessions (session codes and titles) Hands-on Labs (session codes and titles)

31 Track Resources Resource 1 Resource 2 Resource 3 Resource 4

32 Complete an evaluation on CommNet and enter to win! Required Slide

33 © 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. Required Slide


Download ppt "Bart J.F. De Smet Software Development Engineer Microsoft Corporation Session Code: DTL315."

Similar presentations


Ads by Google