How to exclude or lazyload a presenter

materix
Backer | 82
+
0
-

Sometimes when you work on a new presenter (WIP), there a services missing or some code is not complete. This entails that the whole application does not run, because there are some errors with Dependency Injection for this new presenter.

It is possible to exclude a presenter from DI?

m.brecher
Generous Backer | 838
+
+1
-

@materix

Yes, Nette developers sometimes need the possibility to prepare a “concept” of presenter or disable existing presenter which would be invisible for DI, because the class contains errors and work on it will be done later. I think this feature is missing in Nette DI, but would be very useful. One possibility is to add to nette/application attribute #[Disabled] applied to final presenter class like this:

#[Disabled]   // attribute makes presenter invisible for DI
class ArticlePresenter extends BasePresenter
{
   // some code with errors, we plan correct later
}
nightfish
Member | 507
+
+4
-

It is possible to exclude a presenter from DI?

@materix How about making the presenter class abstract?

materix
Backer | 82
+
0
-

nightfish wrote:

It is possible to exclude a presenter from DI?

@materix How about making the presenter class abstract?

Thanks for the work-around idea, which does work.

dkorpar
Member | 135
+
+3
-

Why not having all that in seperate branch and when you're done you put it out? Having code in master which is WIP or does not work does not sounds good IMHO.

materix
Backer | 82
+
0
-

dkorpar wrote:

Why not having all that in seperate branch and when you're done you put it out? Having code in master which is WIP or does not work does not sounds good IMHO.

Thanks for the suggestion. In this case I have multiple WIP-presenters that are not ready, and I want to be able to test the code while coding. But the app is failing because of DI.

Currently using @nightfish suggestion and changing them to abstract classes.

m.brecher
Generous Backer | 838
+
-1
-

@dkorpar

Having code in master which is WIP or does not work does not sounds good IMHO.

I agree. But I have meant just short temporary disabling final presenter classes with #[Disabled], similar like if you comment block of problematic code for 10 – 15 minutes, do another job, than come back, remove disabling attribute and work on solving errors in this presenter. I think would be nice to have something like #[Disabled].

Kamil Valenta
Member | 799
+
+4
-

For Hotfix, just switch branch and then go back to previous branch. The workaround with “abstract” seems to be sufficient, even that should not be needed often (almost never).
I would be careful with the new annotations, you have to remember them because they are not a standard feature of the language.

dkorpar
Member | 135
+
0
-

Sounds like some problems in workflow there…
git also has stash and you should mostly do all the work on seperate branches and then this can't really be a problem… If U have to many active branches then it's also a question of organization, finish what you started then move on to new stuff…

Last edited by dkorpar (2024-09-20 12:24)