Skip to content

Remove paragraph about the impossibility to typehint a property #18756

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

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions service_container/injection_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,11 @@ Another possibility is setting public fields of the class directly::
};

There are mainly only disadvantages to using property injection, it is similar
to setter injection but with these additional important problems:
to setter injection but with this additional important problem:

* You cannot control when the dependency is set at all, it can be changed
at any point in the object's lifetime.

* You cannot use type hinting so you cannot be sure what dependency is injected
except by writing into the class code to explicitly test the class instance
before using it.

But, it is useful to know that this can be done with the service container,
especially if you are working with code that is out of your control, such
as in a third party library, which uses public properties for its dependencies.