How are you doing to deal with class with lots of dependency injections?
Can I store the dependencies in an associate array and pass them in as a one?
class Auth
{
// Set props.
protected $deps;
protected $Database;
protected $Constant;
protected $PasswordHash;
// and so on...
/**
* Construct data.
*/
public function __construct($deps)
{
// Set DI.
$this->deps = $deps;
$this->Database = $this->deps['Database'];
$this->PasswordHash = $this->deps['PasswordHash'];
// and so on...
}
}
In my container,
// Set deps.
$deps = [
"Database" => $Database,
"PasswordHash" => new PasswordHash(HASH_COST_LOG2, HASH_PORTABLE),
// and so on...
];
// Instantiate Auth.
// Provide deps.
$Auth = new Auth($deps);
I haven't done any test with an unit test before. So is this associate array dependency acceptable in the design patter of DI. Can it be tested?
Or any better solutions you have got?