public interface ISomething
{
string SomeMethod(string arg);
}
public class Something : ISomething
{
public Something(Type type)
{
// initialization using type argument
}
public Something(string name)
{
// initialization using name argument
}
public string SomeMethod(string arg)
{
// do something
}
}
public class SomethingElse : ISomethingElse
{
public SomethingElse(ISomething something)
{
// ....
}
}
public class WindsorInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(Component.For<ISomething>().ImplementedBy<Something>().Named("Something").LifestyleSingleton());
}
}
(为简洁起见,我省略了标准的Windsor初始化代码。)
但是当创建ISomethingElse
的实例时(可能是因为ISomethingElse
被注入其他类),Windsor无法解析ISomething
构造函数参数,因为它没有知道为类型参数提供什么。
Castle.MicroKernel.Handlers.HandlerException was unhandled by user code
HelpLink=groups.google.com/group/castle-project-users
HResult=-2146233088
Message=Can't create component 'Something' as it has dependencies to be satisfied.
'Something' is waiting for the following dependencies:
- Service 'System.Type' which was not registered.
- Parameter 'name' which was not provided. Did you forget to set the dependency?