Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is a byte[] of 0 Length being injected into my class?
    text
    copied!<p>I'm using Ninject.Web.WebApi-RC in an MVC 4 Website.</p> <p>In my NinjectWebCommon.cs file I have:</p> <pre><code>kernel.Bind&lt;IA&gt;().To&lt;A&gt;(); kernel.Bind&lt;byte[]&gt;().ToConstant(new byte[1]).WhenTargetHas&lt;AKeyAttribute&gt;(); </code></pre> <p>In my WebApi controller I'm requesting an <code>IKernel</code> in the constructor (just trying to troubleshoot). I'm calling <code>Get&lt;IA&gt;()</code> in my controller constructor. The constructor for <code>A</code> looks like:</p> <pre><code>public A([AKey] byte[] key) </code></pre> <p>where <code>AKeyAttribute</code> is a class that extends <code>Attribute</code>. My issue is that when the code gets inside of the constructor for <code>A</code> its argument is a <code>byte</code> of length 0, not 1.</p> <p>Any ideas? Thanks!</p> <p><strong>EDIT</strong></p> <p>This is incredibly weird. I've changed the constructor of <code>A</code> to:</p> <pre><code>public A([AKey] string test) </code></pre> <p>And my NinjectWebCommon.cs file to:</p> <pre><code>kernel.Bind&lt;string&gt;().ToConstant("Test").WhenTargetHas&lt;AKeyAttribute&gt;(); </code></pre> <p>And then <code>"Test"</code> is indeed being injected into the controller. However when I do:</p> <pre><code>public A([AKey] string[] test) kernel.Bind&lt;string[]&gt;().ToConstant(new string[] { "Test" }).WhenTargetHas&lt;AKeyAttribute&gt;(); </code></pre> <p>That doesn't work.</p> <p>I'm guessing when you do an array of something in a class' constructor it's expecting multi-injection? Is there a way to override this?</p>
 

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