Note that there are some explanatory texts on larger screens.

plurals
  1. PONinject: Passing client's assembly as constructor argument and specifying desired implementation from the client using attributes
    primarykey
    data
    text
    <p>I'm new to Ninject and Dependency Injection in general so please excuse my noobness here. =)</p> <p>I have several implementations of an <code>IConfig</code> interface which scan an Assembly and its dependencies for types implementing an <code>IConfigOption</code> interface. Each <code>IConfig</code> implementation retrieves their values from different sources.</p> <p>These implementations take the root Assembly from where to start scanning as a constructor argument, and I'm trying to come up with a binding that injects these values. So far I'm thinking of something in the lines of:</p> <pre><code>Bind&lt;IConfig&gt;().To&lt;Config&gt;().WithConstructorArgument("rootAssembly", target); </code></pre> <p>My problem is, I can't seem to find a way to get a reference to the <code>target</code> Assembly where the <code>Config</code> class would be injected. Without DI, I would use <code>Assembly.GetCallingAssembly()</code>, but in this context this yields the Assembly where the binding resides, and not the target one as desired.</p> <p>Also, I need a way of specifying the intended implementation <strong>from the class/member that will receive the injection</strong>, so that for example, client class A asks for a <code>Config</code> implementor that uses <code>RoleEnvironment</code> and client class B asks for a <code>Config</code> implementor that uses <code>ConfigurationManager</code>. Here's an example to clarify the intended usage:</p> <pre><code>public class Client { [UseApplicationConfig] public IHelper WithAppConfig { get; set; } [UseRoleEnvironmentConfig] public IHelper WithRoleEnvironmentConfig { get; set; } } public class Helper : IHelper { public Helper(IConfig config) { } } </code></pre> <p>I get the feeling that either I'm looking at this from the wrong angle or I'm missing the obvious, but i'm not sure what I should be looking for. How would be the best way to do it?</p> <p>Thank you very much.</p> <p>EDIT: Added an example of the intended usage and rephrased some parts of the question for clarity.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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