How should dependencies be managed across a modular application?

Posted by bear on Programmers See other posts from Programmers or by bear
Published on 2014-01-03T13:55:12Z Indexed on 2014/06/02 21:45 UTC
Read the original article Hit count: 149

Filed under:
|

Let's say that we have a structure like this:

Application
    -- Modules
        --Module1
            -- Controller
            -- PublicHelper 

        --Module2
           -- Controller
           -- PublicHelper

Whereby a module's Public Helper can provide helper functions.

In nearly every module helper, the helper needs to access another module's public helper methods.

Let's say for instance, in a PHP application:

Module1 provides functionality to create a sale, and as part of the

class Module1PublicHelper extends AbstractModuleHelper {

    public function createSale($customerId, $param, $param)
    {
         $userPublicHelper = // grab an instance of the user public helper
         $currentUser = $userPublicHelper->getCurrentUser();
    }
}

class Module2PublicHelper extends AbstractModuleHelper {

    public function getCurrentUser()
    {
         //do something
         return $user;
    }
}

In this situation, the method needs to obtain an instance, either new or whatever of the user public helper.

Given that all of Module Public Helper classes are instantiated with a minimum set of constructor params, e.g. EntityManager, what would be the best way to get a copy of it?

Obviously, we can't really inject the user public helper class into the class containing createSale

One solution would be to use a service locator or registry, however, testing the application isn't exactly easy.

© Programmers or respective owner

Related posts about php

Related posts about dependency-injection