Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well after a lof of poking around in reflector, I figured this out. By default, the code that finds a constructor for constructor injection calls:</p> <pre><code>ConstructorInfo[] constructors = typeToConstruct.GetConstructors() </code></pre> <p>With no BindingFlags, that will only detect public constructors. With some trickery (as in copy/paste from reflector) you can make a UnityContainerExtension that does all the same stuff as the default implementation, but change the call to GetConstructors() to:</p> <pre><code>ConstructorInfo[] constructors = typeToConstruct..GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) </code></pre> <p>Then add the extension into the unity container. The implemented extenstion is ~100 lines of code, so I didn't paste it here. If anyone wants it, let me know...</p> <p>New working test case. Note that all the Unity created classes are now internal:</p> <pre><code>[TestFixture] public class UnityFixture { [Test] public void UnityCanSetInternalDependency() { UnityContainer container = new UnityContainer(); container.AddNewExtension&lt;InternalConstructorInjectionExtension&gt;(); container.RegisterType&lt;HasInternalDep, HasInternalDep&gt;(); container.RegisterType&lt;TheDep, TheDep&gt;(); var i = container.Resolve&lt;HasInternalDep&gt;(); Assert.IsNotNull(i); Assert.IsNotNull(i.dep); } } internal class HasInternalDep { internal HasInternalDep(TheDep dep) { this.dep = dep; } internal TheDep dep { get; set; } } internal class TheDep { } </code></pre> <p>I'm sure I can make an extension to do the same to resolve non-public properties, but that code was a lot more complicated :)</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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