Inject Request int Service

25 days ago

iwory
Member | 145
+
0
-

Hello,
I would like to get instance of Nette\Application\Request to my own service.

But I don't know how can I inject it because everytime I get error message Parameter $name in Nette\Application\Request::__construct() has no class type hint or default value, so its value must be specified

Is there some way how to?

Thank you

25 days ago

CZechBoY
Member | 2549
+
0
-

Why do you need that? Pass value from AppRequest in presenter if you really need that.

25 days ago

David Matějka
Moderator | 5028
+
+2
-

Application request is not a service (there may be multiple app requests in a single http request), but you can inject Nette\Application\Application and get a current request from there

25 days ago

iwory
Member | 145
+
0
-

CZechBoY wrote:

Why do you need that? Pass value from AppRequest in presenter if you really need that.

I need it because I have service for prepare parameters and don't want to write it in presenter :)

25 days ago

iwory
Member | 145
+
0
-

David Matějka wrote:

Application request is not a service (there may be multiple app requests in a single http request), but you can inject Nette\Application\Application and get a current request from there

Yes, it works. Thx a lot

25 days ago

David Matějka
Moderator | 5028
+
0
-

I need it because I have service for prepare parameters and don't want to write it in presenter :)

well then may be better to follow @CZechBoY recommendation and pass the current Request object to the method you probably call from a presenter

25 days ago

iwory
Member | 145
+
0
-

David Matějka wrote:

I need it because I have service for prepare parameters and don't want to write it in presenter :)

well then may be better to follow @CZechBoY recommendation and pass the current Request object to the method you probably call from a presenter

Ok, I will follow recommendation from @CZechBoY and pass it from a presenter.

23 days ago

dkorpar
Member | 44
+
-1
-

You can inject Nette\Http\IRequest without any problems, I'm using it in severalservices, even in AOP…