Ok, it confirms what I was thinking.
But one of the goals of DI is to give flexibility and externalize (or
"invert") the class instanciations too.
So what if the end user wants to change the Paginator class ?
Should I set the class name as a DI parameter and then use it to
create my class ? example:
$class = $this->container->getParameter('ecommerce.paginator.class');
$adapterClass = $this->container-
>getParameter('ecommerce.paginator.adapter.class');
$adapter = new $adapterClass($query);
new $class($adapter);
Do you think it's a good idea?
Thanks btw,
Florian.
On 7 déc, 09:19, Fabien Potencier <fabien.potenc...@symfony-
project.com> wrote:
> On 12/6/10 9:06 PM, Florian wrote:
>
> > Ok I should have reformulated my question:
>
> > I know it's actually impossible to do that, but the goal of my
> > question is: How to bypass the problem ?
>
> A Paginator is probably not an object you want to manage with the DIC.
>
> The DIC is good at managing "global" objects like a logger, the user
> (from the session), a database connection, ... all the objects for which
> you only need one instance. For everything else, the DIC is not the
> solution (like your model objects for instance -- you need many
> articles, products, ...).
>
> Fabien
>
>
>
>
>
>
>
> > Do I have to modify the lib to work with setters injection ?
>
> > On Dec 6, 8:59 pm, Florian<[email protected]> wrote:
> >> Hi,
>
> >> simple question:
>
> >> Is it possible to inject dependency at runtime with SF2 DI container ?
>
> >> For example, I'm using a Zend\Paginator\Paginator who needs an adapter
> >> as first argument of its constructor.
> >> This adapter needs a Doctrine Query object as first argument of its
> >> constructor too.
>
> >> Can I inject the Query object at runtime, like this ?
>
> >> $this->container->getPaginatorService($query);
>
> >> Thanks!
> >> Florian.
--
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 users" 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-users?hl=en