8000 [DIC] Prototype scope: Injecting a prototype service into a normal service shouldn't require non-strict references · Issue #12585 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DIC] Prototype scope: Injecting a prototype service into a normal service shouldn't require non-strict references #12585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rassilon opened this issue Nov 27, 2014 · 3 comments

Comments

@rassilon
Copy link

Using a prototype scope service from a container scope service shouldn't throw a 'Scope Crossing Injection detected' exception.

This appears to have occurred before 2.6 was released via 803dd58.

It does seem weird to me that prototype is even a special kind of scope. Symfony 1.0 DI called this shared: true/false. This is how I think DIC systems should treat non-shared services (that don't use factory patterns). Scopes should alter major service lifecycle events, and shared/non-shared is just how many instances the DIC ends up creating over the life of the scope.

Thoughts? The fix appears as simple as ignoring prototype scopes in the referenced service definition in CheckReferenceValidityPass:validateScope.

Thanks,
Bill

@fabpot
Copy link
Member
fabpot commented Dec 29, 2014

I understand your concern; however, I'm not sure we can change this behavior as it has been changed very long ago (before the release of 2.0 actually.) Anyway, I truly believe that using prototypes in the service container is almost always a mistake; we don't have any example in Symfony core and everytime someone give an example, it's a wrong usage of prototypes (not sure if this is the case for your use case though.)

I would even go as far as proposing to remove the prototype scope for 3.0.

@rassilon
Copy link
Author
rassilon commented Jan 2, 2015

Using the prototype scope is an easy way of using the factory pattern in the DI container. Otherwise you end up with additional factory services that ONLY have one method: create(). Seems a bit silly, but I understand what kind of complexity it adds to the DI container. Although, not as nearly as much as having scopes in the first place.

@stof
Copy link
Member
stof commented Jan 2, 2015

@rassilon for most factories, you would still need to create a separate one, because it is common to pass arguments to the factory.
And the goal is to be able to discuss the removal of scopes from the container for 3.0, given that the request scope is already deprecated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0