Import Cardinality, and Picking Which Export to Use

In the Managed Extensibility Framework (MEF), an import has a cardinality, which expresses how many exports can be used to satisfy the import.  The possible values are ZeroOrOne, ExactlyOne, or ZeroOrMore, and they can be declared in the following ways: [Import(AllowDefault = true)] IService ZeroOrOneImport { get; set; } [Import] IService ExactlyOneImport { get; set;…

0

A Crash Course on the MEF Primitives

With the Managed Extensibility Framework (MEF), you can use Import and Export attributes to declare what a class consumes and what it offers.  For example, below is an example of two different shapes and a toolbox that imports all available shapes. [Export(typeof(Shape))] public class Square : Shape { // Implementation } [Export(typeof(Shape))] public class Circle…

3

MEFGrid: A Sample MEF Application

MEFGrid is a sample MEF application that I presented at Seattle Code Camp and at an Olympia .NET user group meeting.  It includes connect 4 and the game of life, but other grid based games could be written and dropped into the extensions directory. The application demonstrates some of the more advanced features of MEF. …

1