In the application I am coding myself (MVC) I am using dependency injection to pass an object its dependencies. I don't want to use the Singleton pattern or a dependency injection container.
When the application starts up it has some procedural code instantiating important objects like this: (It loads up more objects than below but they should be enough to explain what I am on about)
/*
* ------------------------------------------------------
* INSTANTIATE THE APPLICATION CLASS
* ------------------------------------------------------
*/
$app = new App();
$app->environment('development');
/*
* ------------------------------------------------------
* INSTANTIATE THE CONFIGURATION CLASS
* ------------------------------------------------------
*/
$config = new Config();
/*
* ------------------------------------------------------
* INSTANTIATE THE LOGGER CLASS
* ------------------------------------------------------
*/
$logger = new Logger($config);
/*
* ------------------------------------------------------
* INSTANTIATE THE LOCALE CLASS
* ------------------------------------------------------
*/
$locale = new Locale();
/*
* ------------------------------------------------------
* INSTANTIATE THE HTTP RESPONSE CLASS
* ------------------------------------------------------
*/
$httpResponse = new HttpResponse();
/*
* ------------------------------------------------------
* INSTANTIATE THE ROUTER CLASS
* ------------------------------------------------------
*/
$router = new Router($config, $logger, $httpResponse);
$router->route();
As you can see the $logger object depends on the $config object and I inject the $config object into the $logger objects constructor.
Now, as you can see when I am instantiating the $router object it has 3 dependencies ($config, $logger and $httpResponse).
I just feel it's weird how the $logger object holds the $config object within it so anywhere I inject the $config object and the $logger object into an object like in the $router object I feel like I'm injecting the $config object twice and that it's wrong.
Obiously when I have more and more objects and dependencies it will seem like I am injecting the same object more than two or three times and that will really make me wonder if I'm doing it wrong.
Is what I'm doing ok?
Thanks.