Responsibility of getInstance() on service container? #39599
Unanswered
rschoonheim
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This is called a singleton. You can see the property and the function are both static. We don't want multiple container instances in our application. This methods gives you the single instance or creates it if there isn't one already. Otherwise you would check this every time you want to get the Container instance. More info: https://en.wikipedia.org/wiki/Singleton_pattern?wprov=sfti1 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello Folks,
I'm new here! Trying to write politely. English isn’t my first language, sorry. Feedback is welcome😄.
I was debugging the Laravel service container. It’s pretty awesome in my opinion :D. I have a little question about the
getInstance()
method onIlluminate\Container\Container::class
.Currently it initializes an instance of
Illuminate\Container\Container::class
whenIlluminate\Container\Container::$instance
equals null. Why? In my opinion, isgetInstance()
a getter. Whenever I decide to create a getter it is to expose some data located in the private scope of an object.I think it’s wrong to make
getInstance()
responsible for object initialization? Or am I missing some details?Code
Pull request that makes
getInstance()
responsible for object initializationBeta Was this translation helpful? Give feedback.
All reactions