[dev] Injector musings
Chuck Hagenbuch
chuck at horde.org
Sun May 30 01:20:00 UTC 2010
Quoting Michael M Slusarz <slusarz at horde.org>:
> Quoting Chuck Hagenbuch <chuck at horde.org>:
>
>> Quoting Michael M Slusarz <slusarz at horde.org>:
>>
>>> Thus, the need for something like:
>>> $contents = $injector->getInstance('IMP_Contents', 1 .
>>> IMP::IDX_SEP . 'INBOX');
>>> $contents2 = $injector->getInstance('IMP_Contents', 2 .
>>> IMP::IDX_SEP . 'INBOX');
>>>
>>> Then later on, when I call
>>> $injector->getInstance('IMP_Contents', 1 . IMP::IDX_SEP . 'INBOX');
>>>
>>> I will get the $contents object that was previously instantiated.
>>
>> Ah, okay. So I think what's called here for is a factory. Something like:
>>
>> $contentsFactory = $injector->getInstance('IMP_Contents_Factory');
>> $contents1 = $contentsFactory->getContents(1, 'INBOX');
>> $contents2 = $contentsFactory->getContents(2, 'INBOX');
>>
>> ... etc. The factory can internally manage whether or not a
>> contents object has been created before.
>
> If someone could check out what I just did re: Horde_Editor, that
> would be great. Seems a bit of overkill in that I had to create a
> binder to point to a factory which, in turn, creates the Editor
> object. But I can't figure out another way to do it given the
> current injector API (injector factories do not provide any help
> here).
>
> As mentioned previously, the current injector API seems to have a
> limitation when it comes to run-time configuration. In other words,
> objects that require the same standardized setup but may contain
> different data depending on the run-time environment.
I wonder if injector child scopes might help here. Have you looked at
those? If not, do you have more specific examples of where the current
API is lacking? Or ways you'd like to see it change?
-chuck
More information about the dev
mailing list