Post on 06-May-2015
DAVID GIARD
MCTS, MCSD, MCSE, MCDBAPrincipal Consultant, Sogetiwww.DavidGiard.comDavidGiard@DavidGiard.com
MANAGED EXTENSIBILITY FRAMEWORK
Beta 2
Compile and Deploy
TIGHT COUPLING
DLL
DLL
EXE
MEF
LOOSE COUPLING WITH MEF
Compile and Deploy
Contract
Contract
ContractContract
DLL
DLL
EXE
DLL
MANAGED EXTENSIBILITY FRAMEWORK Applications consists of loosely-coupled
components that are discovered and composed at runtime
ADVANTAGES OF MEF
Loose Coupling Swap Classes at Runtime No Recompile or Redeploy Single Plug-In Architecture
MEF USAGE SCENARIOS
Empower developers to extend your application without modifying it
Provide extra modules to your application, as needed
Use MEF as an platform ecosystem to manage all parts of your application
DEMO
MEFApp(Accounting)
G/L
A/R
A/P
Export
GenSetu
p
Modules for Accounting app
GET STARTED
MEF.CodePlex.com Download and unzip MEF_Beta_2.zip Zip file contains
DLLs Samples Source Code
DEVELOPER STEPS
Import
Export
Set Reference to System.ComponentModel.Composition.dll
Contract Import Export
Catalogs Composition
Contra
cts
MEF
CONTRACTS
[Import(“Contract1”)]String SomeThing {get; set;}
[Export(“Contract1”)]Public string SpecialThing {Get {return “A Value”};}
“A Value”
MEF
CONTRACTS
[Import(“Contract1”)]String SomeThing {get; set;}
[Export(“Contract1”)]Public string MoreSpecialThing {Get {return “A Different Value”};}
“A Different Value”
MEF
INTERFACE CONTRACTS
[Import(typeof(IFoo))]IFoo SomeFoo {get; set;}
[Export(typeof(IFoo))]public Foo: IFoo{…}
new Foo()
MEF
INTERFACE CONTRACTS
[ImportMany(typeof(IFoo))]List<IFoo> BunchOfFoos{get; set;}
[Export(typeof(IFoo))]public Foo1: IFoo{…} new Foo1()
[Export(typeof(IFoo))]public Foo2: IFoo{…} new Foo2()
COMPOSITION
Catalogs TypeCatalog AssemblyCatalog DirectoryCatalog AggregateCatalog PackageCatalog (Silverlight toolkit)
var catalog1 = new DirectoryCatalog(@"c:\MEF\Imports");var container = new CompositionContainer catalog1);container.ComposeParts(this);
DEMO
Using MEF
MEF VS DEPENDENCY INJECTION
RESOURCES http://MEF.codeplex.com http://www.davidgiard.com http://msmvps.com/blogs/kathleen http://blogs.msdn.com/gblock http://tinyurl.com/
TaultyMEFSilverlightVideos NPlus1.org
David Giard, MCTS, MCSD, MCSE, MCDBA
www.DavidGiard.comDavidGiard@DavidGiard.com
USER GROUPS
Great Lakes Area .Net User Group Southfield, MI migang.org
Greater Lansing .Net User Group East Lansing, MI glugnet.org
DAVE’S THOUGHTS
DavidGiard.com TechnologyAndFriends.com
DavidGiard@DavidGiard.com