温莎城堡ISubDependencyResolver:奇怪的问题

发布于 2024-09-19 12:54:44 字数 746 浏览 11 评论 0原文

温莎城堡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>();
  }
}

Castle Windsor 2.5. This fails. Why? Is it designated beahvior or a bug? Seems sub dependency resolvers are not even queried when resolving top-level services.

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>();
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月如刀 2024-09-26 12:54:44

这些是子依赖解析器。它们解决依赖关系,而不是根服务。你到底想做什么?为什么不预先注册对象呢?

These are sub dependency resolvers. They resolve dependencies, not root services. What are you really trying to do? Why not register the object upfront?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文