Le 14/08/2012 22:45, Markus Thielen a écrit :
Hi,
I wonder why there is a ContainerAwareInterface/AbstractClass that is
only being used in conjunction with the complete symfony2 MVC-system -
but not within the component itself...?
Example:
There is a ContainerAwareEventDispatcher class in the EventDispatcher
component. But this class doesnt implement the ContainerAwareInterface
- instead it needs the container as a constructor-arg.
If it *would* implement the interface, it would not change anything as
the ContainerAwareInterface have no use at all within the
DependencyInjection component. The setContainer-method will net get
invoked at all.
As I want my EventDispatcher being part of the DIC-Configuration, I
wrote an EventDispatcher-Wrapper so I am now able to configure my lazy
EventDispatching within the DIC-Configuration - thats nice. But i made
some ugly hacks to inject my container in the EventDispatcherWrapper,
because the ContainerAwareInterface doesnt work.
So, my question is: Am I wrong? Did I miss anything? Or are you guys
interested in a patch i would write for a pull request?
I also attached my wrapper.
Thanks you & regards,
Markus
The DI container does not do any automatic injection based on interface
implemented by a class. So if you define a service needing to receive
the container, you need to inject it explicitly (the id of the container
itself is the special id "service_container").
The interface is used by some other pieces of code which are created
objects and then check if they should inject the container in them or no
by doing an instanceof check. For instance, the ControllerResolver
available in FrameworkBundle will inject the container after
instantiating the controller if it implements ContainerAwareInterface.
And the ContainerAware class is just a convenience for case where you
don't want to write the property and the setter by hand (it would be a
perfect use case for a trait if Symfony was targetting PHP 5.4+ btw)
--
Christophe | Stof
--
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