Factory with parameters in InversifyJS
<p>I'm using <a href="https://github.com/inversify/InversifyJS" rel="nofollow noreferrer">InversifyJS</a> with TypeScript. </p>

<p>Let's say I have a class which has a mixture of injected and non-injected constructor parameters:</p>

<pre><code>@injectable()
export class MyClass {
    constructor(
      foo: Foo, // This thing isn't injectable
      @inject(Bar) bar: Bar // This thing is
   ){
      ...
   }
}
</code></pre>

<p>I would like to inject a factory for this class into some other class and then invoke it with a value for the first parameter.</p>

<pre><code>@injectable()
export class SomeOtherClass {
   constructor(
      @inject("Factory&lt;MyClass&gt;") myClassFactory: (foo: Foo) =&gt; MyClass
   ){
      const someFoo = new Foo();
      const myClass = myClassFactory(someFoo);
   }
}
</code></pre>

<p>My question: <strong>is there some auto-magic in Inversify that will allow me to inject this factory?</strong></p>

<p>The best I've come up with so far is this:</p>

<pre><code>bind&lt;interfaces.Factory&lt;MyClass&gt;&gt;("Factory&lt;MyClass&gt;").toFactory(context =&gt;
    (foo: Foo) =&gt; 
        new MyClass(foo, context.kernel.get&lt;Bar&gt;(Bar))
);
</code></pre>

<p>But that means I'm explicitly <code>new()</code>-ing <code>MyClass</code> and every new injectable dependency of <code>MyClass</code> has to be added here too.</p>

<p>Is there a better way? Perhaps something based on parameter names like <a href="https://github.com/ninject/Ninject.Extensions.Factory/wiki/Factory-interface" rel="nofollow noreferrer">Ninject Factory Extensions</a>?</p>