views:

70

answers:

1

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

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

Krzysztof Koźmic
Problem actually solved (used UsingFactoryMethod instead ISubDependencyResolver)I had session resolver to inject NHibernate session in my MVC-controllers. But then I wanted to implement an utility to inject dependencies (e.g. sessions) to my action filters. That requires direct resolving because I do sth like InjectProperties there.
Vadim Kantorov

related questions