diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index 0819432b..acf3cb95 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -93,7 +93,7 @@ class ServiceProvider(ServiceProviderABC): self._scope = scope def create_scope(self) -> ScopeABC: - sb = ScopeBuilder(ServiceProvider(self._service_descriptors, self._configuration, self._database_context)) + sb = ScopeBuilder(ServiceProvider(copy.deepcopy(self._service_descriptors), self._configuration, self._database_context)) return sb.build() def get_service(self, service_type: type) -> Optional[object]: diff --git a/tests/custom/di/src/di/application.py b/tests/custom/di/src/di/application.py index ec91c6ad..bdb0cdfc 100644 --- a/tests/custom/di/src/di/application.py +++ b/tests/custom/di/src/di/application.py @@ -20,26 +20,23 @@ class Application(ApplicationABC): pass def main(self): - Console.write_line('Scope1') - scope1: Scope = self._services.create_scope() - ts: TestService = scope1.service_provider.get_service(TestService) - ts.run() - dit: DITesterService = scope1.service_provider.get_service(DITesterService) - dit.run() - t = scope1 - b = t.service_provider - scope1.dispose() + with self._services.create_scope() as scope: + Console.write_line('Scope1') + ts: TestService = scope.service_provider.get_service(TestService) + ts.run() + dit: DITesterService = scope.service_provider.get_service(DITesterService) + dit.run() #Console.write_line('Disposed:') #ts1: TestService = scope1.service_provider.get_service(TestService) #ts1.run() - - Console.write_line('Scope2') - scope2: Scope = self._services.create_scope() - ts: TestService = scope2.service_provider.get_service(TestService) - ts.run() - dit: DITesterService = scope2.service_provider.get_service(DITesterService) - dit.run() + + with self._services.create_scope() as scope: + Console.write_line('Scope2') + ts: TestService = scope.service_provider.get_service(TestService) + ts.run() + dit: DITesterService = scope.service_provider.get_service(DITesterService) + dit.run() Console.write_line('Global') self._part_of_scoped() diff --git a/tests/custom/di/src/di/di.json b/tests/custom/di/src/di/di.json index 67ca9bd5..8058551d 100644 --- a/tests/custom/di/src/di/di.json +++ b/tests/custom/di/src/di/di.json @@ -16,7 +16,10 @@ "LicenseName": "", "LicenseDescription": "", "Dependencies": [ - "sh_cpl>=2021.10.0.post1" + "cpl-core==2022.12.0" + ], + "DevDependencies": [ + "cpl-cli==2022.12.0" ], "PythonVersion": ">=3.9.2", "PythonPath": {},