Geeks With Blogs
Jeff Krebsbach

Another 2010 Tech ED discussion added to the blog - MEF - Managed Extensibility Framework -

MEF is a way of automating the addition of DLLs to an executing process.  With MEF utitlities can be added on the fly, and extended as needed.  This allows us greater flexibility to late bind an abstract operation.  Examples may be:  Logging utilities could depend on database, file system, and event log availability.  We may choose to target one or many options for logging.  Deploy the appropriate assemblies for the appropriate logging method to the deployment directory, and at run time the appropriate assemblies will be loaded and executed.

MEF consists of:  Catalog, Exports, and Imports.

Catalogs are the components for extension, exports expose "contracts" of the catalogs, Imports are what leverage the catalogs that have been created.

Take the following control for exporting and importing, and the ASP.Net page.

[Export(typeof(UserControl))]

public class Widget1 : UserControl

{

  [Import]

  public string Message {

       get{return(string) Button.Content;}

                    set{Button.Content=value;}

               }

}


 public MainPage()

 {

            InitializeComponent();

            CompositionInitializer.SatisfyImports(this);

 }


The composition initializer will look for catalogs of type (this).  Since the UserControl will resolve to type this, the condition for extension will be met.  If the DLL is available to the run time, it will be imported on the fly.

 

This gives us an excelent opportunity to late bind an operation to execute logic conditional on deployment environment.  If some environments have logic different than other environments, it may make sense to break apart the assembly logic, and MEF is one more tool to help us do just that.

Posted on Sunday, August 8, 2010 1:32 PM | Back to top


Comments on this post: Managed Extensibility Framework

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © jkrebsbach | Powered by: GeeksWithBlogs.net