Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If i'm not misunderstanding you, why not simply have your GericLogger Constructor take a parameter that is the type of the object. Then do this:</p> <pre><code>ILog = kernel.Get&lt;ILog&gt;(ParameterList); </code></pre> <p>I haven't read up completely yet on Ninject Parameter Lists, but it seems to be a way to inject a parameter type using an IParameterList.</p> <p>EDIT:</p> <p>Looks like this would work like this:</p> <pre><code>ILog = kernel.Get&lt;ILog&gt;(new ConstructorArgument[] { new ConstructorArgument("ClassName", this.GetType().Name) }) </code></pre> <p>Then you have your ILog</p> <pre><code>class GenericLogger : Ilog { GenericLogger(string ClassName) {}; } </code></pre> <p>I didn't test this, just what seems to be from the Ninject source (i'm looking at a recent Ninject2 tree)</p> <p>EDIT:</p> <p>You want to pass ConstructorArgument, not Parameter. Updated to reflect.</p> <p>This code Prints: "Called From Init"</p> <pre><code>class Init { public void Run() { StandardKernel kernel = new StandardKernel( new MyLoader() ); kernel.Get&lt;Tester&gt;( new ConstructorArgument[] { new ConstructorArgument( "ClassName", this.GetType().Name ) } ); } } public class Tester { public Tester(string ClassName) { Console.WriteLine("Called From {0}", ClassName); } } </code></pre> <p>EDIT:</p> <p>Another method which might be useful is to use The Bind().To().WithConstructorArgument() binding, which could be useful when used with either self-binding or with a .WhenInjectedInto() condition.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload