单声道MEF无法正常工作?
我做了一个非常简单的MEF示例,它运行在.NET上, 但在Mono上无法正常工作。单声道MEF无法正常工作?
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
class Program
{
[Import(typeof(ILedController))]
public List<ILedController> Controllers
{
get;
set;
}
static void Main(string[] args)
{
new Program();
}
public Program()
{
compose();
selectController();
Console.ReadLine();
}
private void compose()
{
var catalog = new DirectoryPartCatalog("controllers");
var container = new CompositionContainer(catalog);
container.AddPart(this);
container.Compose();
}
private void selectController()
{
Console.Clear();
Console.WriteLine("Please select the controller to use\n");
byte i = 0;
foreach (var controller in Controllers)
{
Console.WriteLine("\t{0}) {1}", i, controller.ToString());
i++;
}
Console.Write("\nYour selection: ");
var input = Convert.ToInt32(Console.ReadLine());
Controllers[input].DisplayText(10, 10, "Hello World");
}
}
}
这是接口:
using System;
using System.Collections.Generic;
using System.Text;
namespace Vialis
{
public interface ILedController
{
void DisplayText(int x, int y, string text);
}
}
这是第一个实现:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
[Export(typeof(ILedController))]
public class LyanController : ILedController
{
public void DisplayText(int x, int y, string text)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(text);
}
}
}
第二种方案:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel.Composition;
namespace Vialis
{
[Export(typeof(ILedController))]
public class VialisController : ILedController
{
public void DisplayText(int x, int y, string text)
{
Console.SetCursorPosition(x, y);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(text);
}
}
}
这是.NET会发生什么(Windows):
选择控制器:
但使用单声道2.2的组件不加载:
有什么建议吗?
信息:谷歌似乎有一些picasa网络问题, 这就是为什么图像不加载。
图片显示,在Mac OS上,没有列出控制器。
随着最新的MEF版本(预览版4 - http://www.codeplex.com/MEF),它工作得很好!
由于错误不再相关,我投票结束了这个问题。
谢谢你让我们知道,蒂莫西。我借调了你的投票。 – 2009-02-01 08:04:08
所以我假定出口在外部组件定义,因为您使用DirectoryPartCatalog ..要么有一个与目录或问题的文件路径的处理的一个问题是在AttributedAssemblyPartCatalog/AttributedTypesPartCatalog
内部的DirectoryPartCatalog包装每一个发现的组件插入到AttributedAssemblyPartCatalog这反过来使用AttributedTypesPartCatalog
最好的办法是到MEF项目DirectoryPartCatalog的贪婪的构造函数添加到您的解决方案,而不是DLL,并设置一个断点& AttributedAssemblyPartCatal OG和步骤,直到ü找到问题
不幸的是我没有一个单一的机器设置,所以我不能帮助比
更添加接口和两个实现的应用程序组件的工作。 所以我会按照你的建议进行调试,但是需要为单声道找到一个体面的调试器。
我将从传递给DirectoryPartCatalog的路径开始 - 我只有一种感觉,但它确实听起来像是单声道(可能在OSX上)处理路径与Windows上的NETFX不同。 – TheCodeJunkie 2009-01-26 10:24:41
在我的新闻阅读器图片显示正确(谷歌阅读器),但在本网站上,他们不是...奇数 – TimothyP 2009-01-25 14:59:01