0

I have a class Handler. In the constructor I have a Manager class which depends on different settings.

kernel.Bind<IHandler>().To<Handler>().
                WithConstructorArgument("manager", 
                new Manager(kernel.Get<IDataAccessFactory>().CreateUnitOfWork(), new Custom1Settings()));

How do i create an injection for Custom1Settings in Manager and which in Handler

 class Handler
{
    Handler(IManager manager....)
    {
        ...
    }
}

class Manager
{
    Manager(IUnitOfWork unit, ISettings settings)
    {
        ...
    }
}
Chris
  • 3,329
  • 1
  • 30
  • 44
Mediator
  • 14,951
  • 35
  • 113
  • 191

2 Answers2

0

Ninject automatically figures out dependencies. It's one of it's most useful features.

Define a binding for Custom1Settings and Manager and it will automatically inject it.

So

kernel.Bind<IManager>().To<Manager>();
kernel.Bind<ICustom1Settings>().To<Custom1Settings>();
Sam Leach
  • 12,746
  • 9
  • 45
  • 73
0
kernel.Bind<IManager>().To<Manager>().Named("Registration").WithConstructorArgument("settings", new Custom1Settings());

kernel.Bind<IHandler>().To<Handler>().WithConstructorArgument("manager", ctx => ctx.Kernel.Get<IManager>("Registration"));
Mediator
  • 14,951
  • 35
  • 113
  • 191