'Castle Windsor event DependencyResolving not working

I'm using Castle Windsor v5.1.1 and trying to add a facility and add handler for event DependencyResolving, but get handler isn't called at all. What am I missing?

using Castle.Core;
using Castle.MicroKernel.Facilities;
using Castle.MicroKernel.Registration;
using Castle.Windsor;

var container = new WindsorContainer();
container.Kernel.AddFacility<OverrideFacility>();
container.Register(Component.For<IFoo>().ImplementedBy<Foo>().LifestyleTransient());
container.Resolve<IFoo>();

public interface IFoo { }
public class Foo : IFoo { }

public class OverrideFacility : AbstractFacility
{
    protected override void Init()
    {
        Kernel.DependencyResolving += Kernel_DependencyResolving;
    }
    private void Kernel_DependencyResolving(ComponentModel client, DependencyModel model, object dependency)
    {
        Console.WriteLine("Kernel_DependencyResolving");
    }
}

Container Events: https://github.com/castleproject/Windsor/blob/master/docs/container-events.md#dependencyresolving

Test case: https://github.com/castleproject/Windsor/blob/28e7afaf04462d74d6ad05505dc426b81cf5d9a3/src/Castle.Windsor.Tests/KernelEvents_DependencyResolving_TestCase.cs#L32

EDIT:

Ok, so i just figured out that if I'm resolving a service without dependencies (like Foo above), the event handler isn't called. However, if I have an dependecy like Bar below the handler is called when trying to resolve it's depdency IFoo:

public interface IBar { }
public class Bar : IBar { public Bar(IFoo foo) { } }

So there it seems I can't use the event for resolving the "main" service; the one requested with container.Resolve<>()? Or is there any other way I can achieve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source