title: Dependency Injection in Nunit test classes via contructor or properties
body: <p>I have IInterface with appropriate realization Realization which is registered in IUnityContainer (Unity framework):</p>
  <pre><code>public interface IInterface
  {
      void Foo();
  }
  
  public class Realization : IInterface
  {
      public void Foo() =&gt; Console.WriteLine(&quot;Test&quot;);
  }
  
  public class BaseFixture
  {
      protected IUnityContainer Container { get; set; }
  
      [OneTimeSetUp]
      public void OneTimeSetUp()
      {
          Container = new UnityContainer()
              .RegisterType&lt;IInterface, Realization&gt;();
      }
  }
  </code></pre>
  <p>I have Nunit TestFixture class in which I try to resolve the dependency in two ways:</p>
  <p><strong>Constructor</strong>:</p>
  <pre><code>[TestFixture]
  public class MyTestClass1: BaseFixture
  {
      public IInterface MyProp { get; set; }
  
      public MyTestClass1(IInterface instance)
      {
          MyProp = instance;
      }
  
      [Test]
      public void MyTest1()
      {
          MyProp.Foo();
      }
  }
  </code></pre>
  <p><strong>Property</strong>:</p>
  <pre><code>[TestFixture]
  public class MyTestClass2 : BaseFixture
  {
      [Dependency]
      public IInterface MyProp { get; set; }
  
      [Test]
      public void MyTest2()
      {
          MyProp.Foo();
      }
  }
  </code></pre>
  <p>In the first case(constructor injection) I have the next exception on the runtime:</p>
  <pre><code>OneTimeSetUp: No suitable constructor was found
  </code></pre>
  <p>In the second case (property injection) the property is not initialized and has <code>null</code> value.</p>
  <p>I would appreciate if anybody can advice the solution to use property or constructor injection.
  The only solution I've googled is: <a href="https://github.com/kalebpederson/nunit.dependencyinjection" rel="nofollow noreferrer">https://github.com/kalebpederson/nunit.dependencyinjection</a>,
  but not sure that it is the best one.</p>
  <p>Thanks.</p>