Open SpareParts opened 2 years ago
Thanks for this suggestion!
To help my research, can you point out where other containers are doing something similar?
Sure! php-di has DI\factory()
helper function that autowires the callable and allows to specify arguments that can't be autowired.
Specifically this part:
return [
'Database' => DI\factory(function ($host) {...})
->parameter('host', DI\get('db.host')),
];
Currently the only kind of factory autowiring Capsule supports is to always inject full Container object.
I'm proposing using autowiring for factory callables as well. Analyze arguments and try to autowire them, use some kind of fluent syntax to provide values for arguments that can't be autowired (in the same/similar way we already do for classes).