CodeIgniter Forums
Is the single_service function mis-named? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Feature Requests (https://forum.codeigniter.com/forumdisplay.php?fid=29)
+--- Thread: Is the single_service function mis-named? (/showthread.php?tid=72489)



Is the single_service function mis-named? - AvalonSys - 12-28-2018

There may be a confusing naming issue between the service() and single_service() functions.

If I'm reading the docs right (at: https://codeigniter4.github.io/userguide/concepts/services.html#convenience-functions), the service() function effectively returns a singleton ("shared") object,  while the single_service() function, somewhat counter-intuitively, returns a new object. 

Does anyone else find this confusing and kinda backwards? 

Assuming I've read the docs correctly, it would make more sense to me to change "single_service()" to "new_service()" or something that makes it clear that you're NOT getting a singleton object from the function. Either that, or maybe swap the function names around?


RE: Is the single_service function mis-named? - donpwinston - 12-29-2018

"new_service" would be better then swapping the names.


RE: Is the single_service function mis-named? - dave friend - 12-29-2018

Maybe the problem is the term singleton. It should probably be changed to Sheraton. Big Grin