all InfoSec news
Symfony's magic: dependency injection
May 17, 2023, 11:08 a.m. | jmau111⭐⭐⭐
DEV Community dev.to
Injecting dependencies is a fundamental principle that is recommended by various approaches, including SOLID.
More pragmatically, instead of doing this:
namespace App\Services;
class MyService {
private $myDependency;
public function __construct()
{
$this->myDependency = new MyDependency();
}
}
You can do that (PHP 8):
namespace App\Services;
class MyService {
public function __construct(private MyDependency $myDependency)
{}
}
However, you may wonder why it's better and how it works behind the scene.
Injections …
app beginners class dependencies dependency doing function injection magic namespace php private programming public services solid symfony
More from dev.to / DEV Community
Jobs in InfoSec / Cybersecurity
Social Engineer For Reverse Engineering Exploit Study
@ Independent study | Remote
Cyber Security Culture – Communication and Content Specialist
@ H&M Group | Stockholm, Sweden
Container Hardening, Sr. (Remote | Top Secret)
@ Rackner | San Antonio, TX
GRC and Information Security Analyst
@ Intertek | United States
Information Security Officer
@ Sopra Steria | Bristol, United Kingdom
Casual Area Security Officer South Down Area
@ TSS | County Down, United Kingdom