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?
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.
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.
The CompositionContainer does have a ComposeParts method, as an extension method.
See this reference for some working code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With