我在使用Castle Windsor尝试注册WPF ICommands时看到一些奇怪的行为。Castle Windsor无法解决实现WPF ICommand的类
当运行包含的代码,我得到以下错误:
无法创建组件“ConsoleApplication1.TestParent”,因为它有依赖关系得到满足。
ConsoleApplication1.TestParent等待以下相关:
键(与特定键部件),将其未注册
testChild。
但是,如果我将TestChild上的接口从ICommand更改为ITest,那么代码工作得很好。
有没有其他人目睹这种行为和/或知道如何解决它?
我使用VS2008,.NET 3.5和Castle 2.5.2。
感谢,
斯图尔特
using System;
using System.Windows.Input;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.Register(
Component.For<TestParent>().ImplementedBy<TestParent>(),
Component.For<TestChild>().ImplementedBy<TestChild>()
);
var parent = container.Resolve<TestParent>();
}
}
public interface ITest {}
public class TestParent
{
public TestParent(TestChild testChild) { }
}
public class TestChild : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter) { return true; }
public void Execute(object parameter) {}
}
}
我在.NET 4和Castle 2.5.1中遇到同样的问题。我发现它与ICommand接口上的TypeConverter属性(通过反编译器找到它)有关。 Castle似乎并不喜欢使用特定的TypeConverter。 – 2011-08-11 20:58:40