in this article, I'll show you how to inject configuration values into your custom service using service factory.
Create mail_module.services.yml file:
services:
app.mailer:
class: Drupal/mail_module/Mailer
factory: Drupal/mail_module/MailerFactory:create
arguments: ['@config.factory']
Create MailerFactory.php file:
class MailerFactory {
static function create($config) {
return new Mailer($config->get('mail.config')->get('transport'));
}
}
Create MailerFactory.php file:
class Mailer {
public function __construct($transport) {
$this->mailTransport = $transport;
}
}