-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] The generated code for lazy non-shared services doesn't work #38327
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
Comments
/cc @nicolas-grekas |
fabpot
added a commit
that referenced
this issue
Oct 1, 2020
This PR was merged into the 5.1 branch. Discussion ---------- [DI] fix dumping non-shared lazy services | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #38327 | License | MIT | Doc PR | - It took me a while to get this correct, but here we are. Commits ------- e33a0b0 [DI] fix dumping non-shared lazy services
@nicolas-grekas services.yml: Acme\FooClass:
public: true
lazy: true
shared: false getFooClassService.php: use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
// This file has been auto-generated by the Symfony Dependency Injection Component for internal use.
// Returns the public 'Acme\FooClass' service.
if ($lazyLoad) {
return $this->createProxy('FooClass_704b59e', function () {
return \FooClass_704b59e::staticProxyConstructor(function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
$wrappedInstance = $this->factories['Acme\\FooClass'](false);
$proxy->setProxyInitializer(null);
return true;
});
});
}
include_once \dirname(__DIR__, 4).'/Acme/FooClass.php';
$this->factories['Acme\\FooClass'] = function ($lazyLoad = true) {
return new \Acme\FooClass();
};
return $this->factories['Acme\\FooClass'](); |
@vkurdin-aw can you please open a new issue with a reproducer? |
@nicolas-grekas done #40642 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Symfony version(s) affected: >=5.1.3
Description
When a service is declared as lazy and non-shared, generated code uses
$this->factories['service_name'](false);
inside proxy without initialization of$this->factories['service_name']
before.How to reproduce
The generated getNonSharedFooService looks like this:
Possible Solution
This bug comes from this commit - symfony/dependency-injection@37d0137 (#37435)
when I change back this
to this
it works well.
The text was updated successfully, but these errors were encountered: