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")? Thanks in advance. On Wed, Mar 16, 2011 at 6:57 PM, Gustavo Adrian <[email protected] > wrote: > Hi Johannes, > > No, or at least I don't know how to do it. It's the first time I use the > scope feature. Just adding scope="prototype" to my "UserService" and I get > the exception I described before. > > If the way I described should work, I'll try to reproduce it in a unit > test. > > > > Thanks for your answer! > > Best regards. > > On Wed, Mar 16, 2011 at 6:27 PM, Johannes Schmitt <[email protected]>wrote: > >> On first sight, this looks like a bug. Could it be that you added a custom >> scope? >> >> Kind regards, >> Johannes >> >> On Wed, Mar 16, 2011 at 10:16 PM, Gustavo Adrian < >> [email protected]> wrote: >> >>> Hi all, >>> >>> I'm having some issues with service scoping. I'll try to describe my >>> situation the best I can. If something is not clear, please tell me :). >>> >>> Having this base classes: >>> >>> , Module (which can have services) >>> . Service (which can have other services) >>> >>> I could have something like this: >>> >>> UserModule has a UserService, which can have a ContactInformationService. >>> ContactInformationModule has another instance of ContactInformationService. >>> >>> So, for the first case, I define in the DIC a "user_module" service, a >>> "user_service", and a "contact_information_service". Then, in the >>> "user_module"'s definition, I add the "user_service" to the "user_module" >>> with a call to a Module's method called "addService". Finally, in the >>> "user_service"'s definition, I add to it the sub-service >>> "contact_information_service" with a call to the method "addService". >>> >>> My problem: Each Module should be instantiated only once. This is OK. But >>> each Service should be instantiated once per Module and each time it's been >>> added to a service, as a sub-service. This is because each service can have >>> a different state, depending on if it's a subservice or not. So, I tried to >>> change the scope of my services to "prototype" to accomplish this. But then >>> I received the following error: >>> >>> *"Scope Crossing Injection detected: The definition >>> "module_manager.module.user" references the service >>> "module_manager.module.user.service" which belongs to another scope >>> hierarchy. This service might not be available consistently. Generally, it >>> is safer to either move the definition "module_manager.module.user" to scope >>> "prototype", or declare "container" as a child scope of "prototype". If you >>> can be sure that the other scope is always active, you can set the reference >>> to strict=false to get rid of this error"* >>> >>> I tried to use strict="false" but then I've got an infinite recursion >>> problem. >>> >>> Is my approach correct in terms of the DIC? I mean, is it possible to >>> have, in one hand, one service with scope="container" and add to it services >>> with scope="prototype" and, in the other hand, have a service with >>> scope="prototype" and add to it another service with the same scope? >>> >>> I hope I'm clear. If not, please tell me. >>> >>> >>> >>> Thanks! >>> >>> -- >>> 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 >> > > -- 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
