Skip to content
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

Delegate to the container the creation from dependencies #6550

Open
CrochetFeve0251 opened this issue Apr 9, 2024 · 0 comments
Open

Delegate to the container the creation from dependencies #6550

CrochetFeve0251 opened this issue Apr 9, 2024 · 0 comments

Comments

@CrochetFeve0251
Copy link
Contributor

CrochetFeve0251 commented Apr 9, 2024

Describe the bug
Currently while wiring the classes we are instantiating dependencies.

However, this is something we should not do cause it moves the instantiation from dependencies inside the service provider and not anymore inside the definition.

The main difference here being that the definition is called when the actual is needing for instantiation and not when the whole provider needs to be registered.

To Reproduce
Use Xdebug

  1. Go to any provider
  2. Check when the dependency is instantiated
  3. Removed the $this->getContainer()->get on the dependency
  4. Check when the dependency is instantiated

Expected behavior
Developers should pass dependencies this way:

		$this->getContainer()->add( 'slack_subscriber', Subscriber::class )
			->addArgument( 'pagespeed_results_query' );

instead of:

		$this->getContainer()->add( 'slack_subscriber', Subscriber::class )
			->addArgument( $this->getContainer()->get( 'pagespeed_results_query' ) );

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

Acceptance Criteria (for WP Media team use only)
Clear instructions for developers, to be added before the grooming

@CrochetFeve0251 CrochetFeve0251 changed the title Delegate to the container the creation from Delegate to the container the creation from dependencies Apr 9, 2024
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

1 participant