On 3/20/10 4:54 PM, Bernhard Schussek wrote:
Hi,
I agree with most of the points stated above.
2010/3/20 Fabien Potencier<[email protected]>:
function indexAction()
{
$this->container->getUserService()->setAttribute(...);
}
I don't like the bundling to the container at all for reasons of testability.
I also don't like any magic like $this->services['xxx'] or
$this->__requirements_ = array() etc. Again, it requires a lot of
overhead and understanding for testing.
My preferred solution is a combination of #2 and #3:
### Inject the needed services in the constructor
### Inject services as protected properties
If I require a service in (almost) all actions, Symfony can pass it to
the constructor (like "doctrineManager"). If I only need it in some
actions, Symfony can pass it to the action directly (like "mailer").
Right, mixing the two approaches probably gives the most flexibility to
the developer.
The discussion about whether services or request parameters should be
preferred is void, because a method cannot accept two arguments with
the same name anyway. E.g., if you have a route parameter "user" and a
service "user", you will have to rename either of them to access both.
Alternatively, Symfony can (as suggested above) prefer to inject the
service, but that is confusing because then some route parameters are
injected while others are not.
Why not simply use service aliases? If a route parameter and a service
conflict, give the service an alias and use that instead. The only
problem:
* Service aliases have to be defined upon service definition. How can
I add aliases to services provided by Symfony or a plugin?
Not really an option. An alias does not remove the old name, so you
won't avoid the conflict.
Some further questions:
* Is it possible to activate "autowiring" (guessing injected services
by introspecting parameters) for other classes or methods too?
Right now, no. But of course it is possible. I remember someone wrote an
extension to the Symfony DIC to manage annotations.
* How do I need to name the argument if the requested service ID
contains dots ("user.session.pdo")?
It's not defined yet, but to be coherent with the way we convert service
names to upper case, I think it will be $user_Session_Pdo.
Fabien
Bernhard
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en
To unsubscribe from this group, send email to symfony-devs+unsubscribegooglegroups.com or
reply to this email with the words "REMOVE ME" as the subject.