microsoft managed extensibility framework

11

Click here to load reader

Upload: binu-bhasuran

Post on 12-Jul-2015

141 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Microsoft Managed Extensibility Framework

Binu BhasuranMicrosoft MVP Visual C#

Facebook http://facebook.com/codeno47

Blog http://proxdev.com/

Page 2: Microsoft Managed Extensibility Framework

The Managed Extensibility Framework or MEF is a library for creating lightweight, extensible applications. It allows application developers to discover and use extensions with no configuration required. It also lets extension developers easily encapsulate code and avoid fragile hard dependencies. MEF not only allows extensions to be reused within applications, but across applications as well.

Page 3: Microsoft Managed Extensibility Framework

Instead of this explicit registration of available components, MEF provides a way to discover them implicitly, via composition.

MEF model requires no hard dependency on a particular application assembly, it allows extensions to be reused from application to application.

Page 4: Microsoft Managed Extensibility Framework

MEF is an integral part of the .NET Framework 4, and is available wherever the .NET Framework is used. You can use MEF in your client applications, whether they use Windows Forms, WPF, or any other technology, or in server applications that use ASP.NET.

Page 5: Microsoft Managed Extensibility Framework

private Program(){

//An aggregate catalog that combines multiple catalogsvar catalog = new AggregateCatalog();//Adds all the parts found in the same assembly as the Program classcatalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));

//Create the CompositionContainer with the parts in the catalog_container = new CompositionContainer(catalog);

//Fill the imports of this objecttry{

this._container.ComposeParts(this);}catch (CompositionException compositionException){

Console.WriteLine(compositionException.ToString());}

}

Page 6: Microsoft Managed Extensibility Framework

[Import(typeof(ICalculator))]

public ICalculator calculator;

[Export(typeof(ICalculator))]

class MySimpleCalculator : ICalculator

{

}

[Import(typeof(ICalculator))] public ICalculator calculator;

Page 7: Microsoft Managed Extensibility Framework

[ImportMany]

IEnumerable<Lazy<IOperation, IOperationData>> operations;

[Import(typeof(ICalculator))] public ICalculator calculator;

Page 8: Microsoft Managed Extensibility Framework
Page 9: Microsoft Managed Extensibility Framework

http://msdn.microsoft.com/en-us/library/ms730214.aspx

Page 10: Microsoft Managed Extensibility Framework
Page 11: Microsoft Managed Extensibility Framework