Hi,

I've been very impressed with the Dependency Injection framework of
symfony and the awesome documentation that accompanies it, so thanks
for that.

I do have a question regarding the sfServiceContainer::getService
interface. Let's say I have a class that has the following
constructor:
  Foo::__construct($a, $b);
And let's further say that $a and $b are generated during the course
of running the program and cannot be determined when the application's
dependency graph is wired up.

It feels like I have two options:
  1) I can remove $a and $b from the constructor and instead have them
set via a secondary "init" method that I call after I get the service
instance.
  2)  I can use sfServiceContainer::set_parameters() before calling
getService(). This would allow me to set the values of $a and $b,
which would then make them available in Foo's service definition.

The problem with #1 is that I prefer that objects are as complete as
possible after construction and find requiring a secondary method init
() method error prone.

The problem with #2 is that I'm putting data that is only valid for a
single invocation of getService() into the "global" sfServiceContainer
context. This could cause a problem if another portion of the
application started relying on those parameters. I could work around
this by subsequently removing the parameters after the object is
constructed (or cloning the container), but this is clearly a messy
work around.

What'd I'd rather do is this:
 sfServiceContainer::getService('foo', array('paramA' => 1, 'paramB'
=> 2)).

This would make paramA and paramB available during this single
construction of Foo, but not pollute the sfServiceContainer context
for subsequent calls into getService.

Does adding this extension to getService make sense? I can help with a
patch if the consensus is yes.

Thanks,
EJ

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to