Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy loading for dependencies #2

Closed
mnapoli opened this issue Sep 6, 2012 · 1 comment
Closed

Lazy loading for dependencies #2

mnapoli opened this issue Sep 6, 2012 · 1 comment
Assignees

Comments

@mnapoli
Copy link
Member

mnapoli commented Sep 6, 2012

Given the simple example:

use DI\Annotations\Inject;

class Class1 {
    /**
     * @Inject
     * @var Class2
     */
    private $class2;
}

Private property $class2 will be injected when Class1 is instantiated, i.e. even if not used. This can impact the performances. Lazy loading could be an optimization.

One solution could be to inject proxy instances instead of the dependency. The proxy can catch method and property calls using __get, __set, __call... When used, the proxy can then load the dependency, and forward the call.

mnapoli added a commit that referenced this issue Sep 7, 2012
@ghost ghost assigned mnapoli Sep 7, 2012
mnapoli added a commit that referenced this issue Sep 8, 2012
mnapoli added a commit that referenced this issue Sep 19, 2012
@mnapoli
Copy link
Member Author

mnapoli commented Sep 19, 2012

Implementation:

use DI\Annotations\Inject;

class Class1 {
    /**
     * @Inject(lazy=true)
     * @var Class2
     */
    private $class2;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant