di icon indicating copy to clipboard operation
di copied to clipboard

Referencing original arguments in service alteration

Open matej21 opened this issue 8 years ago • 2 comments

  • bug report? no
  • feature request? yes

When you are altering a service you sometimes need to use args of the original service.

An implementation should be quite easy, so a syntax is the only question.

maybe sth like this:

services:
	application.presenterFactory:
		factory: App\TestPresenterFactory(%self.factory%)
		alteration: yes

what do you think? Any better ideas?

matej21 avatar Jun 26 '17 17:06 matej21

Or this can keep original arguments:

services:
	application.presenterFactory:
		factory: App\TestPresenterFactory
		alteration: yes

dg avatar Aug 20 '17 17:08 dg

Or this can keep original arguments:

services:
	application.presenterFactory:
		factory: App\TestPresenterFactory
		alteration: yes

Should this keep the original arguments now?

The docs look like it should – they do not say the arguments are removed, only that they can be removed via reset. (https://doc.nette.org/cs/3.0/di-services#toc-modifikace-sluzeb, https://doc.nette.org/en/3.0/di-services#toc-modification-of-services).

But the code resets the arguments, when new factory/create is specified (https://github.com/nette/di/blob/086748fee8773b4ca5add34952cc54972de60f07/src/DI/Extensions/ServicesExtension.php#L89, https://github.com/nette/di/blob/038da8e9fb5178fae7657c9318c484a1c556ea17/src/DI/Definitions/ServiceDefinition.php#L74).

What is the intended (default) behavior – reset or keep?

redwormik avatar Dec 20 '21 11:12 redwormik