160 likes | 381 Views
SESSION CODE: DEV304. How and When to Use MEF: Too Much Is Never Enough . Jon Flanders Title MCW Technologies. Managed Extensibility Framework (MEF). MEF is a framework for creating loosely-coupled, extensible applications This has always been possible with .NET
E N D
SESSION CODE: DEV304 How and When to Use MEF: Too Much Is Never Enough Jon Flanders Title MCW Technologies
Managed Extensibility Framework (MEF) • MEF is a framework for creating loosely-coupled, extensible applications • This has always been possible with .NET • Interfaces+classes+dynamic assembly loading • MEF is a standardization of this pattern • Much of Visual Studio 2010 uses MEF • Its extensibility layer relies on it heavily
MEF in a nutshell • MEF centers around three main concepts • Catalog • Exports • Imports • Catalogs contain components that are to be composed • Exports expose “Contracts” • Classes or properties • Imports are properties that require Exported instances • Composition pulls it all together
MEF in action NameTitleCompany DEMO
MEF Basics… Export it. Import it. Composeit.
Export it. [Export(typeof(UserControl))] public class Widget1 : UserControl { public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 UserControl Export
Import it. [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 String Import
Import it. [Export(typeof(UserControl))] public class Widget1 : UserControl { [Import(“HelloMEF.Message”)] public string Message { get{return(string) Button.Content;} set{Button.Content=value;} } } Widget1 “HelloMEF.Message” Import
Import it. [Export(typeof(UserControl))] public class MainPage: UserControl { [ImportMany(typeof(UserControl))] public IEnumerable<UserControl> { get;set; } } Main Page UserControl ImportMany
Compose it. PartIntializer: “Compose yourself” public MainPage() { InitializeComponent(); CompositionInitializer.SatisfyImports(this); } MainPage Compose
MEF in an application NameTitleCompany DEMO
Resources Learning • Sessions On-Demand & Community • Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning • Resources for IT Professionals • Resources for Developers • http://microsoft.com/technet • http://microsoft.com/msdn
Related Content • Interactive Sessions • DEV05-INT | What's Wrong with My .NET Extensible MEF Application? • Session Type: Interactive Session • Thursday, June 10 | 8:00 AM - 9:15 AM | Rm 347 • Track: Developer Tools, Languages & Frameworks • Speaker(s): Daniel Plaisted • Level: 300 - Advanced • Hands-on Labs • DEV06-HOL | Introduction to Managed Extensibility Framework
© 2010 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.