Hi Christophe,

But having a container-scoped service ("module") that has either a
container-scoped service "service" or a prototype-scoped service "service"
is the same thing, and is valid in both cases, at least in this particular
case, as my "module" service will always have only one instance of
"service". So when I get the "module" service using "$container->get(
'module' );" I know it will have always the same instance of "service". It
can't have a different instance each time I get the "module" service, but it
doesn't mean it's wrong. Even if both had a scope "prototype" would still be
correct, because each instance of "module" would have one instance of
"service". I guess that's why exists the "strict" attribute to bypass the
error? for this use cases? If that's the case then I only have to add that
attribute. But I prefer to ask so I'm sure I'm not misunderstanding
something.

The real problem (at least in this particular case) would be in the other
way around. If my "module" were prototyped-scoped and my "service" were
container-scoped, then I would have a global "service" with its state shared
between all my "modules", so the state of the "service" wouldn't be
reliable. What I didn't try is if this throws the same error. I guess in
some use case it could be valid too. So it really depends on the use case.

In brief, the scope verifies if a service is really instantiated the way it
defines it, right? meaning, if a service has a scope "prototype", but its
contained in a service with scope "container", knowing that in each call to
"get" on the container-scoped service won't be a new instance of the
prototype-scoped service, it throws an error. The problem seems to be with
services like my "service", which is valid in both cases, contained in a
container-scoped service, or a prototype-scoped service, which is solved
disabling the "strict" attribute.

Does any of what I said make sense? It's better to learn this stuff now than
when it's too late :)

Oh, and one more question. Container scope means only one instance.
Prototyped means a new instance each time you get the service. What I don't
know is: How does the custom scopes work?



Thanks in advance.



On Wed, Mar 16, 2011 at 11:21 PM, Christophe COEVOET <[email protected]> wrote:

> Le 17/03/2011 02:08, Gustavo Adrian a écrit :
>
>  Using strict="false" in all the references to services with
>> scope="prototype" seems to ignore the problem, as suggested by the
>> exception. The thing is that I still don't understand what could be the
>> problem in this case. Maybe I'm doing something wrong and bypassing the
>> error could cause major problems later. I'll expand a little the situation
>> described before. If someone could explain why a service with scope =
>> container can't have references to services with scope = prototype, I'd be
>> very grateful.
>>
>> My services:
>>
>> "module_manager" (has many "module" services). Scope: container
>> "module" (has many "service" services). Scope: container
>> "service" (could have many "service" services): Scope: prototype
>>
>> If I add strict="false" in each reference of services "service" when I add
>> them to the "module" service, it doesn't throw the exception.
>>
>> Which could be the problem if a single instantiated service (in this
>> particular case, "module") has a reference to a service which can be
>> instantiated many times (in this particular case, "service")?
>>
> the scope says when a service is valid. A container-scoped service is
> always valid (you get the same instance each time) but a prototype-scoped
> service is only valid once (you need to create a new instance each time). So
> injecting a prototype-scoped service in a container-scoped service cannot
> work as you will not recreate a "service" each time you get the "module" so
> you will use the prototype-scoped service as if it were container-scoped.
>
> --
> 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 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
>

-- 
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

Reply via email to