Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Any entity controller (form, access, render, storage etc.) can implement the \Drupal\Core\Entity\EntityControllerInterface
to have their services injected.

Without service injection:

<?php
class ExampleEntityViewBuilder extends EntityViewBuilder {
  public function
buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
   
parent::buildContent($entities, $displays, $view_mode, $langcode);
   
$site_name = Drupal::config()->get('system.site')->get('name');
  }
}
?>

With proper service injection:

<?php
class ExampleEntityViewBuilder extends EntityViewBuilder implements EntityControllerInterface {
 
/**
   * Constructs a new ExampleEntityViewBuilder object.
   */
 
public function __construct($entity_type, array $entity_info, ConfigFactory $config_factory) {
   
parent::__construct($entity_type, $entity_info);
   
$this->config = $config_factory->get('system.site');
  }
 
/**
   * {@inheritdoc}
   */
 
public static function createInstance(ContainerInterface $container, $entity_type, array $entity_info) {
    return new static(
$entity_type, $entity_info, $container->get('config.factory');
  }
  public function
buildContent(array $entities, array $displays, $view_mode, $langcode = NULL) {
   
parent::buildContent($entities, $displays, $view_mode, $langcode);
   
$site_name = $this->config->get('name');
  }
}
?>
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done