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
Post a Comment