Skip to main content
changed the title and the question, since it's not asking how to inject services in a generic class, but how to inject services in a class used to implement a service
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do I inject services in class that implements an interfacea service?

How do I inject services in a class that implements an interface.service?

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The aboveI am using the following code, but it throws an error.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

How do I inject services in class that implements an interface?

How do I inject services in a class that implements an interface.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The above code throws an error.

How do I inject services in a service?

How do I inject services in a service?

I am using the following code, but it throws an error.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}
edited title
Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do I inject services in class that implements an interface?

Tweeted twitter.com/StackDrupal/status/823666658229231617
edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How to injectsdo I inject services in class if itthat implements Interfacean interface

How do I inject services in a class if itthat implements an interface.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The above code throws an error.

How to injects services in class if it implements Interface

How do I inject services in a class if it implements an interface.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The above code throws an error.

How do I inject services in class that implements an interface

How do I inject services in a class that implements an interface.

class RoleNegotiator implements ThemeNegotiatorInterface {

  public static function create(ContainerInterface $interface) {
    return new static(
      $interface->get('router.admin_context')
    );
  }
  public function __construct(RouteMatchInterface $route) {
    $this->route = $route;
  }
}

The above code throws an error.

improved formatting and grammar
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284
Loading
Source Link
harsh_behl_0007
  • 1.2k
  • 1
  • 11
  • 21
Loading