title: Getting an instance of a class that uses dependency injection
body: <p>I've been reading about <em>dependency injection</em>, and I'm getting the basics. Most of the examples on the internet explain it till here:</p>
  
  <pre><code>public class MyClass
  {
      private IDependency _dependency;
  
      public MyClass(IDependency dependency)
      {
          _dependency = dependency;
      }
  }
  </code></pre>
  
  <p>This way, we inject the <em>dependency</em> through the <em>constructor</em>. But I don't think it's a good idea to keep writing:</p>
  
  <pre><code>var myClassInstance = new MyClass(someArgument);
  </code></pre>
  
  <p>all throughout the code. Should I use the factory pattern to get instances?</p>
  
  <pre><code>public static class MyClassFactory
  {
      private static IDependency dependency = DependencyFactory.GetInstance();
  
      public static MyClass GetInstance()
      {
          return new MyClass(dependency);
      }
  }
  </code></pre>
  
  <p>Is this the way to go?</p>
  
  <p>I know that using a DI container solves the problem, but I'd like to learn how to incorporate dependency injection in my code, before using a DI container.</p>