0

Ninject has this method.

public IBindingToSyntax<T1, T2, T3, T4> Bind<T1, T2, T3, T4>()

Is it possible somehow extend this method to bind 5 interfaces to one implementation?

Like this:

public IBindingToSyntax<T1, T2, T3, T4, T5> Bind<T1, T2, T3, T4, T5>()
Ruslan_K
  • 423
  • 7
  • 23

1 Answers1

0

Ninject provides a fluent syntax that allows you to bind up to 4 interfaces together to the same instance:

Bind<IInterface1, IInterface2, IInterface3, IInterface4>().To<Implementation>();

If we need more interfaces there is a workaround:

var bindingConfiguration =
    Bind<IInterface1, IInterface2, IInterface3, IInterface4>()
        .To<Implementation>()
        .BindingConfiguration;
kernel.AddBinding(new Binding(typeof(IInterface5), bindingConfiguration));

Below I posted a quote from author why only four interfaces?

Some may ask what is if I want to bind more than four interface to the same service. In a small discussion we came to the conclusion that if you have more than four interfaces on a single service than most likely you have a problem with the single responsibility principle and should fix this in first place.

Link to article New Features and changes of Ninject 3.0

Ruslan_K
  • 423
  • 7
  • 23