Welcome Guest, Not a member yet? Register   Sign In
CI 4.4.0 modules shared services not working

(This post was last modified: 08-30-2023, 05:30 AM by davis.lasis.)

(08-30-2023, 04:27 AM)ozornick Wrote: In Services:
return static::getSharedInstance('Alert');
Remove ?? new Alert()

service('Alert') to lowercase service('alert')

Did you replicate this? 
I tried your options - no luck, it does not work.

I changed Autoload

PHP Code:
'Modules'    => ROOTPATH 'Modules'

PHP Code:
'Modules\Base'    => ROOTPATH 'modules\Base'

and now it throws infinite loop error

PHP Code:
Fatal errorAllowed memory size of 536870912 bytes exhausted (tried to allocate 262144 bytesin ..\system\Config\BaseService.php on line 267 

PHP Code:
public static function serviceExists(string $name): ?string
        static::buildServicesCache(); // this is line 267
        $services array_merge(self::$serviceNames, [Services::class]);
        $name    strtolower($name);

        foreach ($services as $service) {
            if (method_exists($service$name)) {
                return $service;

        return null;

Old version (4.3.7) serviceExists() and buildServicesCache() code are the same. So it should be something related to Module autoloading... Or maybe caching is changed, cause i never use it

(08-30-2023, 04:34 AM)kenjis Wrote: Did you really work with v4.3.x?
App\Config\Autoload.php should be:

PHP Code:
    public $psr4 = [
        APP_NAMESPACE => APPPATH// For custom app namespace
        'Config'      => APPPATH 'Config',
        'Modules\Base'    => ROOTPATH 'Modules/Base'// my custom modules

See https://codeigniter4.github.io/CodeIgnit...namespaces

Weird question. Yes i do work with CI since v2 till now, always updating main core with newest version.

I had magic legacy method in Autoload which loaded all modules and Services worked fine in each module

PHP Code:
$modules array_filter(glob('../Modules/*'), 'is_dir');

        if (!empty($modules)) {
            foreach ($modules as $key => $module_path) {
                if (str_contains($module_path'/')) {
                    $split_path explode('/'$module_path);
                    if (array_key_exists(2$split_path)) {
                        $this->psr4['Modules\\'.$split_path[2]] = ROOTPATH.'modules/'.$split_path[2];

Messages In This Thread
RE: CI 4.4.0 modules shared services not working - by davis.lasis - 08-30-2023, 04:41 AM

Theme © iAndrew 2016 - Forum software by © MyBB