How do I instantiate a custom class with dependency injection? I am relatively fresh to the DI party and am struggling to get my head around how exactly to use Dependency Injection.
I understand that I can pass requirements as part of a service, but what about in my own class?

Say I have the below class where I want the language manager service to be injected:

class Foo implements ContainerInjectionInterface {

  protected $languageManager; 

  public function __construct(LanguageManagerInterface $languageManager) {
    $this-&gt;languageManager = $languageManager;
  }

  public static function create(ContainerInterface $container) {
    return new static(
      $container-&gt;get('language_manager')
    );
  }
}


When I call new Foo() I am required to pass an instance of LanguageManagerInterface. That makes sense in terms of a normal constructor method, but that would require me to instantiate the class like the below:

$languageManager = \Drupal::service('language_manager');
$foo = new Foo($languageManager)


That just doesn't feel right to me.

Is there something I am missing, or would this class always have to be a service to take advantage of dependency injection?
A class implementing ContainerInjectionInterface is instantiated by calling the factory method create().

See Drupal\Core\DependencyInjection\ClassResolver

/**
 * Implements the class resolver interface supporting class names and services.
 */
class ClassResolver implements ClassResolverInterface, ContainerAwareInterface {
  use DependencySerializationTrait;
  use ContainerAwareTrait;

  /**
   * {@inheritdoc}
   */
  public function getInstanceFromDefinition($definition) {
    if ($this-&gt;container-&gt;has($definition)) {
      $instance = $this-&gt;container-&gt;get($definition);
    }
    else {
      if (!class_exists($definition)) {
        throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $definition));
      }

      if (is_subclass_of($definition, 'Drupal\Core\DependencyInjection\ContainerInjectionInterface')) {
        $instance = $definition::create($this-&gt;container);
      }
      else {
        $instance = new $definition();
      }
    }

    if ($instance instanceof ContainerAwareInterface) {
      $instance-&gt;setContainer($this-&gt;container);
    }

    return $instance;
  }

}