Closed tfleis closed 8 years ago
Hi,
this is a known limitation. It's the same for all other resources and classes that are injected by mvvmFX (like @InjectViewModel
, @InjectRessourceBundle
).
Using the public void initialize()
method is the recommended way for initialization of ViewModels.
Some details to understand the reason for this behaviour: Internally the following steps are done when a ViewModel is requested:
MyViewModel.class
from DI container@Inject
into that instance@PostConstruct
public void initialize()
on the ViewModelThe postconstruct method is already called before we get the instance for the first time.
By the way, this process is the reason why we need special annotations like @InjectScope
instead of just using @Inject
.
I can understand your feature request but at the moment there is no way of implementing it. At the moment the loading process is independ from a specific DI container. The ViewLoader simply asks whatever DI container is available for new instances (or creates it by itself if none is available). To implement this feature the ViewLoader would need to know which DI container is running at the moment and the loading would need to be DI container specific.
I've added a section for livecycles and post construct in the wiki.
Hi Manuel,
thank you for the explanation. We will switch from @PostConstruct
to public void initialize()
.
You can close this issue.
The scope is injected after PostConstruct annotated method is called. As workaround we use "public void initialize()" instead of PostContruct annotation.