Caller Info Attributes in Portable Class Libraries

With the release of .NET 4.5 and Visual Studio 2012, C# and Visual Basic support Caller Info attributes which provide a simple way to get information about the caller of a method.  This can be useful for tracing and diagnostic methods and can also make it easier to implement INotifyPropertyChanged.  For example, you can use…

2

How to Make Portable Class Libraries Work for You

A Portable Class Library is a .NET library that can be used (in binary form, without recompiling) on multiple .NET platforms.  When you create a Portable Class Library in Visual Studio, you can choose which platforms to target.  Portable libraries support targeting the .NET Framework, Silverlight, Windows Phone, Windows Store apps, and XBox 360 XNA…

13

How To Control Who Can Write Extensions For Your MEF Application

With the MEF DirectoryCatalog, it is easy to load extensions from a given directory for a MEF Application.  The DirectoryCatalog will scan any assemblies in that directory and find MEF extensions in those assemblies.  This means that adding an extension to a MEF application can be as easy as dropping a DLL in an extensions…

3

How to Debug and Diagnose MEF Failures

The Managed Extensibility Framework (MEF) helps make it easy to write extensible applications.  We hope that it is simple to understand the basics and get started.  However, MEF brings with it the possibility of new types of failures.  Without the proper knowledge, these failures can be difficult to diagnose.  This blog post will cover some…

12

Presentation at TechEd North America 2010

TechEd North America 2010 is in a few weeks, and I will be giving a presentation on MEF.  Below is the session description: DEV05-INT | What’s Wrong with My .NET Extensible MEF Application? Thursday, June 10 | 8:00 AM – 9:15 AM | Rm 347 The Managed Extensibility Framework (MEF) is a powerful new technology…

0

Overriding MEF Metadata

The Managed Extensibility Framework (MEF) is designed to allow open-ended extensibility.  It is easy to define a contract and load extensions which satisfy the contract.  This is accomplished with a collection import, which can look like this:[ImportMany] public IPlugin[] Plugins { get; set; } Extensions may need to be ordered or prioritized Often, the importer…

2

Podcast with Me on Testing on the MEF Team and at Microsoft

This week I was on the Herding Code podcast, discussing how we do testing on the MEF team and at Microsoft.  You can listen to it here. This was the first podcast I’ve been on and I enjoyed it quite a bit.  Some lessons learned: When recording a podcast over Skype, make sure you have…

1

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