In the controller, I could do
$this->get('service.name')
But in a custom class, how can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Define your custom class as a service, and then inject dependencies into it.
Ex:
Your custom class’ constructor would then get those services as arguments.
Be sure to read up on the Service Container in the official docs. It goes over all this in great detail.