title: Binding multiple versions of the same type with Ninject
body: <p>I am using Ninject to create a set of "plugins", e.g. I have:</p>
  
  <pre><code>Bind&lt;IFoo&gt;().To&lt;Class1&gt;(); 
  Bind&lt;IFoo&gt;().To&lt;Class2&gt;();
  Bind&lt;IFoo&gt;().To&lt;Class3&gt;();
  </code></pre>
  
  <p>... and later on I use <code>kernel.GetAll&lt;IFoo&gt;()</code> and iterate over the results. Each of <code>Class1/Class2/Class3</code> implement <code>IFoo</code> of course, and have constructors that have a bunch of parameters also injected by Ninject, for example the constructor for <code>Class1</code> is <strong><code>public Class1(IBar bar, IBaz baz)</code></strong>, with both <code>IBar</code> and <code>IBaz</code> injected by Ninject. So far so good. </p>
  
  <p>However, now I want to have two different "versions" of <code>Class1</code>, both bound to <code>IFoo</code>, differing only in a value passed at construction time. That is, for example, suppose the <code>Class1</code> constructor was now <strong><code>public Class1(IBar bar, IBaz baz, bool myParameter)</code></strong>, and I want to do the following:</p>
  
  <pre><code>Bind&lt;IFoo&gt;().To&lt;Class1&gt;(); //Somehow pass 'true' to myParameter here
  Bind&lt;IFoo&gt;().To&lt;Class1&gt;(); //Somehow pass 'false' to myParameter here
  Bind&lt;IFoo&gt;().To&lt;Class2&gt;();
  Bind&lt;IFoo&gt;().To&lt;Class3&gt;();
  </code></pre>
  
  <p>... Then, when I call <code>kernel.GetAll&lt;IFoo&gt;()</code>, I want 4 versions of <code>IFoo</code> returned (<code>Class1</code> "true" version, <code>Class1</code> false version, <code>Class2</code> and <code>Class3</code>). <strong>I've read through the Ninject documentation and can't find a way to do this.</strong></p>
  
  <p>Here are some ideas I tried, but none of them work well:</p>
  
  <p>1) I could just separate classes (e.g. <code>Class1True</code> and <code>Class1False</code>), with one deriving from another, and bind to them. The problem is that this solution doesn't really scale when I have to do this for many classes - I end up polluting my class hierarchy with a lot of useless classes, and the problem becomes worse when the constructor parameter I want to pass is anything more complex than a bool. Realistic example:</p>
  
  <pre><code>Bind&lt;IDrawingTool&gt;().To&lt;Brush&gt;(); //Somehow pass '5' to brushThickness to create a fine brush
  Bind&lt;IDrawingTool&gt;().To&lt;Brush&gt;(); //Somehow pass '25' to brushThickness to create a medium brush
  Bind&lt;IDrawingTool&gt;().To&lt;Brush&gt;(); //Somehow pass '50' to brushThickness to create a coarse brush
  Bind&lt;IDrawingTool&gt;().To&lt;Pencil&gt;();
  Bind&lt;IDrawingTool&gt;().To&lt;SprayCan&gt;();
  </code></pre>
  
  <p>Of course, this is just one possible configuration of infinitely many possible ones. Creating a new class for each brush thickness seems wrong.</p>
  
  <p>2) I looked into the possibility of using a .ToMethod binding, something like this:</p>
  
  <pre><code>Bind&lt;IDrawingTool&gt;().ToMethod(c =&gt; new Brush(5));
  Bind&lt;IDrawingTool&gt;().ToMethod(c =&gt; new Brush(25));
  Bind&lt;IDrawingTool&gt;().ToMethod(c =&gt; new Pencil());
  </code></pre>
  
  <p>But in this case I'm confused about the following:</p>
  
  <p>a) What if the Brush() constructor actually requires other parameters as well, that must be injected via Ninject?</p>
  
  <p>b) Are multiple ToMethod bindings actually allowed?</p>
  
  <p>c) Would this work with InSingletonScope()?</p>
  
  <p><strong>So to summarize: What is a good way to bind to multiple "versions" of the same type?</strong></p>