Set name of service for inject method

Keeehi
Member | 36
+
0
-

Hi,

My base presenter injects (by inject* method) some service. The problem is that there are two services created from the same class. The services have names, so i can say in config.neon which should be used but:

  1. Base presenter is abstract, so service can't be created from it and I have no idea where else I could configure that.
  2. Even if I could create a service, I don't know how to specify name of service for inject* method. I only know, how to do it in constructor (@service.name)

Workaround for now is that I have to create services in config.neon for all presenters (sooo unnecessary) and specify it in constructors. But because of this one, I have to specify all parameters of all presenters constructors and it is soooo ugly.

So, is there a nice way how to do it that I don't know?

Thanks

CZechBoY
Member | 3608
+
+1
-

You can use decorator extension and setup.

https://doc.nette.org/en/configuring#…

Keeehi
Member | 36
+
0
-

Thanks, that was exactly what I was looking for.

Just one more question. Is it safe to use for a name of the method something that starts with inject? I don't want it to be called twice (once for automatic injection and once for decorator). I run it in debugger and it was called once and with right service, so it works now. I just want to know if the naming could cause some problems in the future.

David Grudl
Nette Core | 8082
+
+2
-

I think it is safe.