Define a custom D8 service class implement ContainerInjectionInterface

Hey, is it possible for a custom service to implement ContainerInjectionInterface?

I have created one service, and the parameter passed to __construct function is always null. Any ideas?



namespace Drupalbix_globalUser;

use DrupalCoreDependencyInjectionContainerInjectionInterface;
use SymfonyComponentDependencyInjectionContainerInterface;
use DrupalCoreDatabaseConnection;

/**
 * Determines BixGlobalUser class.
 *
 * @ingroup bix_global
 */
class BixGlobalUser implements ContainerInjectionInterface {

  /**
   * The injected Database Connection.
   *
   * @var DrupalCoreDatabaseConnection
   */
  protected $DatabaseConnection;

  /**
   * {@inheritdoc}
   */
  public function __construct($connection) {
    $this->DatabaseConnection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity.manager')
    );
  }

  /**
   * Validate the email existence for user account.
   *
   * This function is to replace validation of function user_load_by_mail(),
   * because this function only needs to search one table and works faster.
   *
   * @param $email
   * @return bool
   */
  public function validate_user_email($email) {
    $connection = $this->DatabaseConnection;
    $query = $connection->select('users_field_data','u');
    $query->fields('u', array('uid'))
      ->condition('mail', $email);
    $result = $query->execute()->fetchCol();
    return !empty($result);
  }

  /**
   * Validate the user name existence for user account.
   *
   * This function is to replace validation of function user_load_by_name(),
   * because this function only needs to search one table and works faster.
   *
   * @param $name
   * @return mixed
   */
  public function validate_user_name($name) {
    $connection = $this->DatabaseConnection;
    $query = $connection->select('users_field_data', 'u');
    $query->fields('u', array('uid'))
      ->condition('name', $name);
    $result = $query->execute()->fetchCol();
    return !empty($result);
  }

}

Drupal version: 


Source: https://www.drupal.org/taxonomy/term/4/feed