我在使用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