Auto-inject to all services

Notice: This thread is very old.
lutor
Member | 27
+
0
-

Hi,
in stable version of Nette 2.1 auto-inject of services to properties annotated with @inject is enabled only in presenters. Is there any possibility to how to (for example via config.neon or any other way) turn on auto-injection of services to properties annotated with @inject annotation to all registered services? (as in some older dev-version of Nette 2.1 – RC3/4 I think…).

Thanks!

enumag
Member | 2118
+
0
-

As far as I know there is not. You can enable it manually for desired service using

services:
	name:
		class: ...
		inject: yes

Beware though that using inject annotations and methods anywhere else than in Presenters is not recommended. Constructor injection is prefered.

Majkl578
Moderator | 1364
+
0
-

Sadly, there is no way to change default behavior, not even e.g. static property. But you can write an extension which will walk all services or use Majkl578/nette-injects-extension (which doesn't require public :P).