Inject Request int Service

Notice: This thread is very old.
iwory
Member | 147
+
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

CZechBoY
Member | 3608
+
0
-

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

David Matějka
Moderator | 6445
+
+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

iwory
Member | 147
+
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 :)

iwory
Member | 147
+
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

David Matějka
Moderator | 6445
+
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

iwory
Member | 147
+
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.

dkorpar
Member | 135
+
-1
-

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