tenantService ??= new TenantService( $this->createTenantRepository(), $this->createDepartmentRepository(), $this->createDirectorySettingsGateway() ); } public function createDepartmentService(): DepartmentService { return $this->departmentService ??= new DepartmentService( $this->createDepartmentRepository(), $this->userServicesFactory(), $this->createDirectorySettingsGateway(), $this->createDirectoryScopeGateway() ); } public function createRoleService(): RoleService { return $this->roleService ??= new RoleService( $this->createRoleRepository(), $this->createDirectorySettingsGateway() ); } public function createTenantRepository(): TenantRepository { return $this->tenantRepository ??= new TenantRepository(); } public function createDepartmentRepository(): DepartmentRepository { return $this->departmentRepository ??= new DepartmentRepository(); } public function createRoleRepository(): RoleRepository { return $this->roleRepository ??= new RoleRepository(); } public function createDirectorySettingsGateway(): DirectorySettingsGateway { return $this->directorySettingsGateway ??= new DirectorySettingsGateway( $this->settingServicesFactory()->createSettingGateway() ); } public function createDirectoryScopeGateway(): DirectoryScopeGateway { return $this->directoryScopeGateway ??= new DirectoryScopeGateway( $this->tenantServicesFactory()->createTenantScopeService() ); } private function userServicesFactory(): UserServicesFactory { return $this->userServicesFactory ??= new UserServicesFactory(); } private function settingServicesFactory(): SettingServicesFactory { return $this->settingServicesFactory ??= new SettingServicesFactory(); } private function tenantServicesFactory(): TenantServicesFactory { return $this->tenantServicesFactory ??= new TenantServicesFactory(); } }