Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

Controllers that inject services by extending ControllerBase previously had to implement a create() factory method:

  public function __construct(DateFormatterInterface $date_formatter, RendererInterface $renderer, EntityRepositoryInterface $entity_repository) {
    $this->dateFormatter = $date_formatter;
    $this->renderer = $renderer;
    $this->entityRepository = $entity_repository;
  }

  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('date.formatter'),
      $container->get('renderer'),
      $container->get('entity.repository')
    );
  }

ControllerBase now implements AutowireTrait and in many cases, overriding the create() method is no longer required as the trait takes care of selecting the correct services. In the simplest cases, the services can be inferred from the interfaces alone. If a service cannot be determined from the interface directly you can use the #[Autowire] attribute to specify the service ID:

  public function __construct(
    #[Autowire(service: 'cache.default')]
    protected CacheBackendInterface $cache
 ) {}
Impacts: 
Module developers