title: Ninject error: More than one matching bindings are available
body: <p>I'm messing around with Ninject and MVC and design partterns. In my simple application I have a structure like this:</p>
  
  <p>(the abstract classes)</p>
  
  <ul>
  <li>interface ICoffee</li>
  <li>abstract class Coffee: ICoffee</li>
  </ul>
  
  <p>(couple of classes)</p>
  
  <ul>
  <li>public class  Espresso : Coffee, ICoffee</li>
  <li>public class  Cappuccino: Coffee, ICoffee</li>
  <li>public class  Late: Coffee, ICoffee</li>
  </ul>
  
  <p>(couple of decorator classes)</p>
  
  <ul>
  <li>public class Milk : ICoffee</li>
  <li>public class Chocolate: ICoffee</li>
  </ul>
  
  <p>The decorator classes accept a parameter of type ICoffee , change some settings and then return it.</p>
  
  <p>Then I have the following classes: </p>
  
  <pre><code>  public abstract class CoffeeStore : ICoffeeStore
  {
      private readonly IProcessedOrderFactory processedOrderFactory;
      private readonly IDictionary&lt;string, Func&lt;ICoffee, ICoffee&gt;&gt; condimentsStrategies;
  
      public CoffeeStore(
          IProcessedOrderFactory processedOrderFactory,
          IDictionary&lt;string, Func&lt;ICoffee, ICoffee&gt;&gt; condimentsStrategies)
      {
          if (condimentsStrategies == null)
          {
              throw new ArgumentNullException(nameof(condimentsStrategies));
          }
  
          if (processedOrderFactory == null)
          {
              throw new ArgumentNullException(nameof(processedOrderFactory));
          }
  
          this.processedOrderFactory = processedOrderFactory;
          this.condimentsStrategies = condimentsStrategies;
      }
  
      public IProcessedOrder ProcessOrder(IOrder order)
      {
          ICoffee coffee;
  
          var coffeeType = order.SelectedCoffeeType;
  
          CoffeSizeType coffeeSize;
          Enum.TryParse(order.SelectedCoffeeSize, out coffeeSize);
  
          coffee = this.CreateCoffee(coffeeType, coffeeSize);
  
          foreach (var condimentAsString in order.SelectedCoffeeCodimentsList)
          {
              if (!this.condimentsStrategies.ContainsKey(condimentAsString))
              {
                  throw new ArgumentException(condimentAsString);
              }
  
              //error occurs on the following line:
              coffee = this.condimentsStrategies[condimentAsString](coffee); 
          }
  
          var processedOrder = this.processedOrderFactory.CreateOrder(coffee);
  
          return processedOrder;
      }
  
      // abstract factory method
      protected abstract ICoffee CreateCoffee(string coffeeType, CoffeSizeType size);
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code> public class SofiaCoffeeStore : CoffeeStore
  {
      private readonly IDictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt; strategies;
  
      public SofiaCoffeeStore(
          IProcessedOrderFactory processedOrderFactory,
          IDictionary&lt;string, Func&lt;ICoffee, ICoffee&gt;&gt; condimentsStrategies,
          IDictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt; strategies)
          : base(processedOrderFactory, condimentsStrategies)
      {
          if (strategies == null)
          {
              throw new ArgumentNullException(nameof(strategies));
          }
  
          this.strategies = strategies;
      }
  
      protected override ICoffee CreateCoffee(string coffeeType, CoffeSizeType size)
      {
          if (!this.strategies.ContainsKey(coffeeType))
          {
              throw new ArgumentNullException();
          }
  
          return this.strategies[coffeeType](size);
      }
  }
  </code></pre>
  
  <p>also the ninject registering module looks like this: </p>
  
  <pre><code>private static void RegisterServices(IKernel kernel)
      {
          kernel.Bind(x =&gt; x
           .FromAssemblyContaining&lt;ICoffee&gt;()
           .SelectAllClasses()
           .Excluding&lt;ICoffee&gt;()
           .BindAllInterfaces());
  
          kernel.Bind(x =&gt; x
          .FromAssemblyContaining&lt;ICoffee&gt;()
          .SelectAllInterfaces()
          .EndingWith("Factory")
          .BindToFactory());
  
          kernel.Bind&lt;ICoffee&gt;().To&lt;Americano&gt;().NamedLikeFactoryMethod((ICoffeeTypeFactory f) =&gt; f.GetAmericano(default(CoffeSizeType)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Cappuccino&gt;().NamedLikeFactoryMethod((ICoffeeTypeFactory f) =&gt; f.GetCappucino(default(CoffeSizeType)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Espresso&gt;().NamedLikeFactoryMethod((ICoffeeTypeFactory f) =&gt; f.GetEspresso(default(CoffeSizeType)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Latte&gt;().NamedLikeFactoryMethod((ICoffeeTypeFactory f) =&gt; f.GetLatte(default(CoffeSizeType)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Ristretto&gt;().NamedLikeFactoryMethod((IPlovdivStoreCoffeeTypeFactory f) =&gt; f.GetRistretto(default(CoffeSizeType)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Doppio&gt;().NamedLikeFactoryMethod((ISofiaStoreCoffeeTypeFactory f) =&gt; f.GetDoppio(default(CoffeSizeType)));
  
          kernel.Bind&lt;ICoffee&gt;().To&lt;Caramel&gt;().NamedLikeFactoryMethod((ICondimentsFactory f) =&gt; f.GetCaramel(default(ICoffee)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Chocolate&gt;().NamedLikeFactoryMethod((ICondimentsFactory f) =&gt; f.GetChocolate(default(ICoffee)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Cinnamon&gt;().NamedLikeFactoryMethod((ICondimentsFactory f) =&gt; f.GetCinnamon(default(ICoffee)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;Milk&gt;().NamedLikeFactoryMethod((ICondimentsFactory f) =&gt; f.GetMilk(default(ICoffee)));
          kernel.Bind&lt;ICoffee&gt;().To&lt;WhippedCream&gt;().NamedLikeFactoryMethod((ICondimentsFactory f) =&gt; f.GetWhippedCream(default(ICoffee)));
  
          var sofiaStoreStrategies = new Dictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt;
          {
              { "Americano", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetAmericano },
              { "Capuccino", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetCappucino },
              { "Espresso", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetEspresso },
              { "Latte", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetLatte },
              { "Doppio", kernel.Get&lt;ISofiaStoreCoffeeTypeFactory&gt;().GetDoppio },
          };
  
          var plovdivStoreStrategies = new Dictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt;
          {
              { "Americano", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetAmericano },
              { "Capuccino", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetCappucino },
              { "Espresso", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetEspresso },
              { "Latte", kernel.Get&lt;ICoffeeTypeFactory&gt;().GetLatte },
              { "Ristretto", kernel.Get&lt;IPlovdivStoreCoffeeTypeFactory&gt;().GetRistretto },
          };
  
          var condimentsStrategies = new Dictionary&lt;string, Func&lt;ICoffee, ICoffee&gt;&gt;
          {
              { "Milk", kernel.Get&lt;ICondimentsFactory&gt;().GetMilk },
              { "Caramel", kernel.Get&lt;ICondimentsFactory&gt;().GetCaramel },
              { "Chocolate", kernel.Get&lt;ICondimentsFactory&gt;().GetChocolate },
              { "Cinnamon", kernel.Get&lt;ICondimentsFactory&gt;().GetCinnamon },
              { "Whipped cream", kernel.Get&lt;ICondimentsFactory&gt;().GetWhippedCream },
          };
  
  
          kernel.Bind&lt;IDictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt;&gt;().ToConstant(sofiaStoreStrategies)
              .WhenInjectedInto&lt;SofiaCoffeeStore&gt;();
          kernel.Bind&lt;IDictionary&lt;string, Func&lt;CoffeSizeType, ICoffee&gt;&gt;&gt;().ToConstant(plovdivStoreStrategies)
              .WhenInjectedInto&lt;PlovdivCoffeeStore&gt;();
          kernel.Bind&lt;IDictionary&lt;string, Func&lt;ICoffee, ICoffee&gt;&gt;&gt;().ToConstant(condimentsStrategies)
                  .WhenInjectedInto&lt;CoffeeStore&gt;();
  
         //some more bellow
      }
  </code></pre>
  
  <p>An error occurs in method ProcessOrder (class CoffeeStore). </p>
  
  <pre><code>Ninject.ActivationException occurred
  HResult=0x80131500
  Message=Error activating ICoffee
  More than one matching bindings are available.
  Matching bindings:
  1) binding from ICoffee to Caramel
  2) binding from ICoffee to Chocolate
  3) binding from ICoffee to Cinnamon
   .....
  22) binding from ICoffee to WhippedCream
  Activation path:
  2) Injection of dependency ICoffee into parameter coffee of constructor of type Cinnamon
  1) Request for ICoffee
  Suggestions:
  1) Ensure that you have defined a binding for ICoffee only once.
  </code></pre>
  
  <p>I'm collecting user input as string from 3-stage wizard form and then use it at once for object initialization. Hope the code I shared is enough to get an idea what i'm trying to do next:
  First I want to initialize one of the coffee type classes and then to decorate the object with one or more of the decorator classes.
  The error occurs on the second step - when I try to initialize a decorator class, the first step goes ok. Any idea how to overcome this ? </p>