Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEF: ComposeParts missing

Tags:

I am trying to follow some starter guides for using MEF in .Net 4, but I get stuck when I get to setting up the application. The instructions say to do this:

var catalog = new DirectoryCatalog(@".\");
var container = new CompositionContainer(catalog);
container.Composeparts(this);

But the version of System.ComponentModel.Composition included with .Net 4 doesn't seem to have the Composeparts method available on CompositionContainer, and I am unable to find a good reference on how to do this in the current system.

Here is the reference I am currently using: Building Composable Apps in .NET 4 with the Managed Extensibility Framework

Does anyone out there have a better reference that I should be looking at?

like image 364
Matt Avatar asked Jul 16 '10 18:07

Matt


People also ask

What is MEF used for?

The Managed Extensibility Framework or MEF is a library for creating lightweight, and 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.

What is MEF components in visual studio?

The MEF is a . NET library that lets you add and modify features of an application or component that follows the MEF programming model. The Visual Studio editor can both provide and consume MEF component parts. The MEF is contained in the . NET Framework version 4 System.


2 Answers

The CompositionContainer does have a ComposeParts method, as an extension method.

See this reference for some working code.

like image 63
Ando Avatar answered Oct 19 '22 15:10

Ando


One thing to note, if you haven't used extension methods before. You MUST have the using statement. In this case:

using System.ComponentModel.Composition;

for the code in the question to work. Without the using statement, the intellisense and compiler will not allow the use of the extension method.

like image 30
Paul Osterhout Avatar answered Oct 19 '22 16:10

Paul Osterhout