mvvmFX
mvvmFX copied to clipboard
Injections not working properly
I am trying to use the @InjectedScope on my ViewModel but for some reason it just remains null.
I tried to configure it as shown here https://github.com/sialcasa/mvvmFX/tree/develop/examples/contacts-example/src/main/java/de/saxsys/mvvmfx/examples/contacts/ui but for some reason I don't get anything from the injection.
I have a simple scope class that implements Scope, and in my ViewModel class I just try to inject it to see that it is not null. I there anything else needs to be configured?
Can you show your code?
At what point in time do you check for the scope to be null? For example, you cannot access injected things in the constructor of the viewModel but instead you have to wait until all initialization is done by the framework. The best way for doing this is to create a method an annotate it with @Initialize
, i.e.
public class SomeViewModel implements ViewModel {
@InjectScope
private SomeScope someScope;
@Initialize
private void init() {
someScope.subscribe(...);
}
}
I haven't seen the @Initalize annotation, this might help. I am using spring now for injections so I guess I will keep it that way for now. Thanks :)