Bart JF De Smet bartdemicrosoftcom httpblogsbartdesmetnetbart Software Development Engineer Microsoft Corporation Session Code DTL315 Agenda Why extensibility matters Extensibility the naïve way ID: 477308
Download Presentation The PPT/PDF document "Managed Extensibility Framework" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1Slide2
Managed Extensibility Framework
Bart J.F. De
Smet
bartde@microsoft.com
http://blogs.bartdesmet.net/bart
Software Development Engineer
Microsoft Corporation
Session Code: DTL315Slide3
AgendaWhy extensibility mattersExtensibility the naïve way
MEF versus
System.Addin
Core concepts
Lots of demos
SummarySlide4
Extensibility in pictures
Source:
http://www.gambiastart.nlSlide5
Customer versus developer
Source:
http://www.insidefurniture.com
Source:
http://
cristinalaird.files.wordpress.comSlide6
Extensibility is hard
Looks familiar?
Too hard?Slide7
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…Slide8
Extensibility the naïve wayBart J.F. De SmetSoftware Development Engineer
Microsoft Corporation
demoSlide9
AgendaWhy extensibility mattersExtensibility the naïve wayMEF versus
System.Addin
Core
concepts
Lots of demos
SummarySlide10
Managed Extensibility FrameworkParts
have a
contract
are found in a
catalog
compose in a
container
Square with 4 pins
I have these blocks
Let’s build somethingSlide11
System.Addin in a nutshell
Cross-process or
appdomain
Versioning adaptation
The essence of an add-inSlide12
Is System.Addin overkill?System.Addin
Isolation boundaries
Activation of add-ins
Across CLR versions
MEF
Composition engine
at its coreUtilities for discoverySimple declarative modelAnswer: complimentary technologiesSlide13
AgendaWhy extensibility mattersExtensibility the naïve wayMEF versus System.Addin
Core concepts
Lots of demos
SummarySlide14
A world of give and take
“I
need
”
“I
have
”Slide15
Composition
Host application
Need a
IMathBinOp
Extension A
Have a
IMathBinOp
MEF composition engine
[Export]
[Import]
Part
PartSlide16
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 application
ExtensionSlide17
How to compose?CompositionContainer
Wiring “surface” where magic happens
CompositionBatch
Contains the parts to be wired together
Container
Batch
Part
ComposeSlide18
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
compositionSlide19
Simple compositionBart J.F. De SmetSoftware Development Engineer
Microsoft Corporation
demoSlide20
Advanced topics in import/exportNamed contractsTypically based on TypeCan 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)Slide21
Where do parts come from?Concept of a catalogType catalog – explicit list of typesAssembly catalog –
attributed
types in an assembly
Directory
catalog – based on directory
search
Aggregate catalog – allows combining catalogsUnion operationComposablePartCatalog base classQueryable
for parts (
Parts
)
Search exports for a given import (
GetExports)Slide22
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 pathSlide23
Working with catalogsBart J.F. De SmetSoftware Development Engineer
Microsoft Corporation
demoSlide24
AgendaWhy extensibility mattersExtensibility the naïve wayMEF versus System.Addin
Core concepts
Lots of demos
SummarySlide25
Selection of MEF Preview 6 samplesBart J.F. De SmetSoftware Development Engineer
Microsoft Corporation
demo
http://mef.codeplex.comSlide26
AgendaWhy extensibility mattersExtensibility the naïve wayMEF versus System.Addin
Core concepts
Lots of demos
SummarySlide27
The ABC CCC of MEFSlide28
question & answerSlide29
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
ResourcesSlide30
Related ContentBreakout Sessions (session codes and titles)
Interactive Theater Sessions (session codes and titles)
Hands-on Labs (session codes and titles)
Hands-on Labs (session codes and titles)Slide31
Track ResourcesResource 1
Resource
2
Resource
3
Resource
4Slide32
Complete an evaluation on
CommNet
and enter to win!
Required SlideSlide33
©
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