Skip to content

Replacing object definitions: inconsistent behavior of DI\object() #294

Closed
@mindplay-dk

Description

@mindplay-dk

Per the manual:

A DI\object() definition always extends a previous object definition

So then, what do you do if you need to replace a previous object definition?

The reason for this is to allow to easily extend autowiring and annotations definitions:

This may be the most common use-case, but it's not the only use-case.

DI\object() is the only kind of definition that extends by default: all other definitions override the previous definition completely.

Even had that in bold, because this behavior is inconsistent with the rest of the API.

I would strongly prefer a consistent API to lessen the learning curve (we're a big team) and a dedicated additional function for extending a previous definition, e.g. DI\extend() or maybe DI\override() to make this an explicit operation. (Implicit behavior is risky. Behavior that varies based on previous method calls is confusing.)

This would also eliminate the case where you try to "extend" something that hasn't been defined at all, and potentially end up with something that partially works, but probably not as intended.

(PS: I've opened a few issues by now - feel free to ask me to PR on any of those)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions