0

I use Ninject version="3.2.2.0" and last version of EasyNetQ 0.63.5.454. I've created simple project.

static class Program
{
    static void Main()
    {
        var kernel = new StandardKernel(new NinjectSettings(){LoadExtensions = true});
        kernel.Load<MyModule>();
        kernel.RegisterAsEasyNetQContainerFactory();
        var b = kernel.Get<IBus>();
    }
}

public class MyModule : NinjectModule
{
    public override void Load()
    {
        Kernel.Bind<IBus>().ToMethod(t => RabbitHutch.CreateBus("host=localhost;publisherConfirms=true")).InSingletonScope();
    }     
}

But in line var b = kernel.Get<IBus>(); I get System.StackOverflowException. In the debug mode I see recursive call of Kernel.Bind().ToMethod() though it has Singleton Scope.

Do you have any ideas why it's happens?

Thanks in advance.

  • most likely caused by `RabbitHutch.CreateBus("host=localhost;publisherConfirms=true")`. But that should be visible in the exception details of the `StackOverflowException`? – BatteryBackupUnit Jan 19 '17 at 04:39
  • When we call `kernel.Get()` we go to the `Kernel.Bind().ToMethod`. `RabbitHutch.CreateBus("host=localhost;publisherConfirms=true")` also tries to resolve IBus so we go in the `Kernel.Bind().ToMethod` again. So we get the recursion. May be problem in Ninject may be another. – Denis K Jan 20 '17 at 07:40
  • What you're saying fIMO doesn't make any sense because the `ToMethod` part does *not* lead to *another* request of **IBus**. It's shown in the debugger because of the contents of `ToMethod` being executed on this line. – BatteryBackupUnit Jan 20 '17 at 08:58
  • again: the debugger stops on the line of the binding because the code `RabbitHutch.CreateBus("host=localhost;publisherConfirms=true")` is being executed. So unless the break point is 3+ times on that line there's no recursion due to the binding mechanism itself. However, if `RabbitHutch` somehow is calling `Kernel.Get` then of course there would be a recursion involving the binding. – BatteryBackupUnit Jan 20 '17 at 09:27

0 Answers0