Skip to content

Conversation

@richardmiller-zz
Copy link
Contributor

I have added setter and property injection examples to the Service Container page as per the comments on https://gist.github.com/968411

Is this an appropriate place for them?

Copy link
Member

Choose a reason for hiding this comment

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

You should use the .. note:: or .. tip:: directive here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a .. note:: directive

Added blanks line after namespace decleration in Service Container Page.
@Shurakai
Copy link
Contributor

I think code examples for annotation are missing too.

Furthermore, I suggest to add a note that property injection must be used restrictively and with much care; disadvantages should be listed.

@richardmiller-zz
Copy link
Contributor Author

Are code examples for annotation needed? They are not there for any of the examples already on this page. If they are needed, are they added to the config blocks along with the yaml, xml and php examples?

@richardmiller-zz
Copy link
Contributor Author

With regards to property injection. I agree about adding a note about its use. It certainly feels like the wrong way to do the injection to me. However, gut feeling aside, the only concrete disadvantage I can think of at the moment is not being able to type hint since the property does need to be made public. Anyone got any others I can add?

@weaverryan
Copy link
Member

Per the value of property injection (for non-public properties) - the discussion is being waged here: symfony/symfony#858

The big disadvantage imo is that (if your properties are protected/private), your object can no longer be instantiated in a traditional way - Reflection (or the DIC) must be used to set the properties.

Per the annotations, is there an annotation method that's supported in core? If so, it should be mentioned with the others inside the configuration block, using .. code-block:: php-annotations.

Copy link
Member

Choose a reason for hiding this comment

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

And also, when you add some "warnings" here, it might be ok to say that "Reflection" is used, which is a way of going beyond what PHP normally lets you do. Otherwise, this might confuse someone who's starting to understand OO, but then suddenly sees a protected property being accessed.

@richardmiller-zz
Copy link
Contributor Author

Quite happy to add some warnings about property injection, although after reading the debate about it, would it be better to remove it from this section altogether and have something about it in a cookbook article instead?

@schmittjoh
Copy link
Contributor

I agree.

Regardless of the form of property injection that we will support eventually, it should be clear that the preferred forms of injection are constructor args, and setter injection.

@richardmiller-zz
Copy link
Contributor Author

I can't find anything to suggest that DI by annotation is in core. It doesn't make any sense to me to be specifying the dependency in the class file even in the comments, may as well not use DI at all if you are going to do that. Am I missing something with this?

@weaverryan weaverryan merged commit c0bd2b6 into symfony:master May 16, 2011
@weaverryan
Copy link
Member

Thanks for everyone's comments - I've merged this is (it's an important piece to have included).

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

Labels

None yet

6 participants