Castle Windsor 2.5。这失败了。为什么?是指定行为还是错误?在解析顶级服务时,甚至不会查询子依赖解析器。
class Program
{
class Resolver :ISubDependencyResolver
{
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
return new Program();
}
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
return dependency.TargetType == typeof (Program);
}
}
[STAThread]
static void Main()
{
var container = new WindsorContainer();
container.Kernel.Resolver.AddSubResolver(new Resolver());
var xxx = container.Resolve<Program>();
}
}
答案 0 :(得分:2)
这些是子依赖解析器。它们解决依赖关系,而不是根服务。你真的想做什么?为什么不预先注册对象?