Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two ViewModel instances are created when the view has no field for the ViewModel #181

Closed
manuel-mauky opened this issue Feb 19, 2015 · 1 comment
Milestone

Comments

@manuel-mauky
Copy link
Collaborator

When using the CDI module under some conditions there are two instances of the ViewModel created when we would expect to have only one.

This sounds similar to #124

@manuel-mauky manuel-mauky changed the title CDI: ViewModels are created twice in some situations. Two ViewModel instances are created when the view has no field for the ViewModel Feb 19, 2015
@manuel-mauky
Copy link
Collaborator Author

After a little investigation I found out that this is not a problem specific to CDI but in the main module.

When the View has no field defined for the ViewModel and no injection is happening, two instances of the ViewModel are created.

When a View is requested by the FXMLLoader we create a new ViewModel instance (or take one from DI) and are trying to inject it into the View. If the view has no Field defined for the ViewModel, nothing happens.
A view steps later we try to get the ViewModel instance from the View so we can provide it in the returned ViewTuple. If at this point there is no field in the View, we are creating a new ViewModel instance.

The solution is to create a new ViewModel instance in the ControllerFactory only when there is a Field defined.

manuel-mauky added a commit that referenced this issue Feb 19, 2015
@manuel-mauky manuel-mauky added this to the 1.1.0 milestone Apr 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant