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

BeanFactory.getBean always returns new instance #3

Open
ragavsathish opened this issue Jul 20, 2016 · 1 comment
Open

BeanFactory.getBean always returns new instance #3

ragavsathish opened this issue Jul 20, 2016 · 1 comment

Comments

@ragavsathish
Copy link

BeanFactory.getBean initializes dependency graph every time and creates new instance whenever asked for new bean.

@atennert
Copy link

atennert commented Mar 20, 2019

Hi @ragavsathish,
I just stumbled over this as well. I checked your commits. I thought about setting the isInitialized as well. But while writing a test for it I thought of this:

The createApplication is only calling the getBean function to get the bean AND create the application. The init function of the bean factory is public though. So I was wondering whether:

  • the init function should be private - that would make your solution save as well
  • or whether to remove the call to init from getBean and explicitly call init from outside (createApplication). Then I would suggest putting the check for one execution into the init function and throw an error if there was another call.

I personally think the second solution is cleaner. What are your thoughts about it? I plan on preparing a commit later.

Edit:
I think the expose-BeanFactory script should be on another PR as it has nothing to do with this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants