I have updated Nette from version 2.3 to 2.4 by instruction (https://doc.nette.org/…tions/to-2-4).
However, I have some problems with new version. I used the deprecated class in my code – nette/deprecated/src/Environment.php.
- The class deprecated but what do I use instead? The instruction and code nothing says about replace instance.
- How I can get the Container instance outside Presenters? I can replace some code pieces by Container data, but I did not find information about getting Container instance.
- Member | 126
using container directly is highly discouraged, you should pass only services you need through constructor and not use container at all in code. See: https://doc.nette.org/…introduction. If U have to much of those in presenters then you have also a different kind of problem that won't solve just getting rid of container…
Workaround can be to inject container to presenter and work with it, but that's a bad practice and you should avoid doing it…
From what I see you have a problem in architecture from start (not using DI at all) and this will probably be a pain to resolve.
Last edited by dkorpar (2022-08-02 15:54)
using container directly is highly discouraged
I completely agree with this, but the project is huge and I can not refactor it now.
From what I see you have a problem in architecture from start (not using
DI at all) and this will probably be a pain to resolve.
Exactly, the project has 15 years old legacy.
You may as well replace Environment with your own static class and set
Container to that class in your app/bootstrap.php so it does not stop you from
I have done it. However, I thought have more right way to getting the Container instance.
Thanks for the advices.