开发者

MEF: ComposeParts missing

开发者 https://www.devze.com 2023-01-07 10:53 出处:网络
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:

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 referen开发者_Go百科ce that I should be looking at?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号