Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[DI] Add section about getter injection#7300

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

@nicolas-grekas
Copy link
Member

@nicolas-grekasnicolas-grekas commentedDec 29, 2016
edited
Loading


The disadvantages of getter injection are:

* You must call the getter everytime you need the dependency internally.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

There isn't any property holding the dependency to use anyway. Is it worth mentioning this as a drawback? 😅

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's actually the same drawback as outlined here, reformulated :)

Copy link
Contributor

@ogizanagiogizanagiDec 29, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I meant this should probably not appear in the drawbacks section at all. It isn't one. Just a consequence of the above. Which has no impact.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

oh! removed then!

app.newsletter_manager:
class:AppBundle\Mail\NewsletterManager
getters:
-getMailer:'@mailer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Shouldn't it rather be:

app.newsletter_manager:class:AppBundle\Mail\NewsletterManagergetters:getMailer:'@mailer'getLogger:'@logger'

?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

fixed

@nicolas-grekasnicolas-grekasforce-pushed thegetter-injection branch 2 times, most recently fromf9144d5 tof8d3457CompareDecember 29, 2016 19:11
// ...
abstract class NewsletterManager
{
abstract protected function getMailer(): MailerInterface;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

If these return types are mandatory, we must add somewhere that this only works with PHP 7. Otheriwse, we should remove them.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I forgot to mention that PHP 7 is required when using getter injection. Added now.
About the type hints, they are not required, but highly recommended. Given the PHP 7 requirement, I think we should keep them here.

hhamon, robfrawley, xabbuh, and chalasr reacted with thumbs up emoji
@xabbuhxabbuh added this to the3.3 milestoneDec 30, 2016
----------------

..versionadded::3.3
Getter Injection was introduced in Symfony 3.3.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should mention that this is an experimental feature

Getter Injection
----------------

..versionadded::3.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The leading spaces should be removed.

fabpot added a commit to symfony/symfony that referenced this pull requestJan 30, 2017
This PR was merged into the 3.3-dev branch.Discussion----------[DI] Add getter injection| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets |#20657| License       | MIT| Doc PR        |symfony/symfony-docs#7300Getter overriding by the container will allow a new kind of dependency injection which enables easier laziness and more immutable classes, by not requiring any corresponding setter. See linked issue for more.This is WIP:- [x] wire the concept- [x] dump anonymous classes with PhpDumper- [x] generate at runtime in ContainerBuilder::createService- [x] tests- [x] make it work on PHP 5Commits-------cb49858 [DI] Add getter injection
symfony-splitter pushed a commit to symfony/dependency-injection that referenced this pull requestJan 30, 2017
This PR was merged into the 3.3-dev branch.Discussion----------[DI] Add getter injection| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | #20657| License       | MIT| Doc PR        |symfony/symfony-docs#7300Getter overriding by the container will allow a new kind of dependency injection which enables easier laziness and more immutable classes, by not requiring any corresponding setter. See linked issue for more.This is WIP:- [x] wire the concept- [x] dump anonymous classes with PhpDumper- [x] generate at runtime in ContainerBuilder::createService- [x] tests- [x] make it work on PHP 5Commits-------cb498580d1 [DI] Add getter injection
@xabbuhxabbuh removed the On hold labelJan 31, 2017
// ...
$container->register('app.newsletter_manager', NewsletterManager::class)
->addOverriddenGetter('getMailer', new Reference('mailer'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should besetOverriddenGetter (same below).

@nicolas-grekas
Copy link
MemberAuthor

Reverted, one less thing to document for 3.3 :)

@nicolas-grekasnicolas-grekas deleted the getter-injection branchMarch 25, 2017 20:18
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@javiereguiluzjaviereguiluzjaviereguiluz left review comments

@xabbuhxabbuhxabbuh left review comments

+1 more reviewer

@ogizanagiogizanagiogizanagi left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

6 participants

@nicolas-grekas@fabpot@javiereguiluz@xabbuh@ogizanagi@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp