What's the right way to instantiate router in config?

5 years ago

JirkaChadima
Member | 5
+
0
-

Hi,

after upgrading to Nette 2.1 I keep getting the following error:

PHP User Deprecated: Passing factories to Nette\DI\Container::addService() is deprecated; pass the object itself.

It's obviously caused by the following part of config.neon:

services:
    router:
        factory: \MyRouter::createRouter

What's the proper way of handling this? Even sandbox uses static factory to create Router. If it's the recommended way, why does it fire the User Deprecated error? It's really confusing.

5 years ago

Tomáš Kolinger
Member | 138
+
0
-

try replace “factory” with “class” or use short-annotation, see https://github.com/…/config.neon#L27

Last edited by Tomáš Kolinger (2015-01-13 09:51)

5 years ago

JirkaChadima
Member | 5
+
0
-

When i use class, services are not instantiated at all. Short version works, but the original error is still there.

4 years ago

JirkaChadima
Member | 5
+
0
-

OK, my bad. It was actually triggered by httRequest substitute used in cli execution which was defined as a Closure.