php - Dependency Injection Container and defining all(?) dependencies -


i puzzled define dependencies.

it seems huge overkill load every possible dependency while may not used @ all. defining them @ place of need result in code duplication.

where defined? perhaps configuration of dependency initiated once? example logger or db connection.

thanks in advance.

in work had problem , used approach based on symfony2. have simple dependency container, holds lambda functions used create dependencies might need and, upon first usage, factory called.

something like:

dc['afactory'] = function() { return new a(); }; 

dc has "cache" of dependency objects, every time use dc->get('a'), first check whether caché filled, in case, existent instance, otherwhise, factory function called, stored in cache , results. way don't have load every possible dependency until it's used.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -