-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
resolving() events on interfaces are called twice #23699
Labels
Comments
There has been some attempts to fix this previously in #23290 but it wasn't merged. Perhaps send a PR with your suggested changes? |
Fine, I'll submit a PR these days that will address this issue. This test triggers the problem: public function testResolvingCallbacksAreCalledOnceForImplementations()
{
$invocations = 0;
$container = new Container;
$container->resolving( IContainerContractStub::class, function( ) use ( &$invocations ) {
$invocations++;
} );
$container->bind(IContainerContractStub::class, ContainerImplementationStub::class );
$this->assertEquals( 0, $invocations );
$container->make( IContainerContractStub::class );
$this->assertEquals( 1, $invocations );
} |
"... these days..." |
Fixed in 5.8. |
The bug is still in 5.8.12 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In L5.5, 5.6 I experience an issue with resolving callbacks on dependencies registered in the container with an interface class as abstract. A demonstration:
Having some interface
and an implementation
registered (here as a singleton) in the container
with a resolving callback
fires
$callback
twice when the abstract is resolved!This is probably because:
IBar
resolves, it triggers the callbackIBar
,Foo
must be constructed. AsFoo
implementsIBar
, it triggers theresolving
event too!This problem can be omitted when avoiding Laravel's container to build Foo by registering a callback instead:
But this abolishes the ease of automatic dependency injection.
So... can we solve this issue by not firing the
resolving()
callback when we are building the implementation of an interface that the callback is registered for?The text was updated successfully, but these errors were encountered: