From 943f5ad50bddf0c442c9394d9f512f005d8e3945 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 4 Apr 2023 21:45:32 +0200 Subject: [PATCH] Improved service scope --- .../dependency_injection/service_provider.py | 12 +++++++++--- ...ts-pc-ubuntu.json => appsettings.edrafts-pc.json} | 0 2 files changed, 9 insertions(+), 3 deletions(-) rename tests/custom/general/src/general/{appsettings.edrafts-pc-ubuntu.json => appsettings.edrafts-pc.json} (100%) diff --git a/src/cpl_core/dependency_injection/service_provider.py b/src/cpl_core/dependency_injection/service_provider.py index b7d59e56..8084b936 100644 --- a/src/cpl_core/dependency_injection/service_provider.py +++ b/src/cpl_core/dependency_injection/service_provider.py @@ -127,9 +127,15 @@ class ServiceProvider(ServiceProviderABC): self._scope = scope def create_scope(self) -> ScopeABC: - sb = ScopeBuilder( - ServiceProvider(copy.deepcopy(self._service_descriptors), self._configuration, self._database_context) - ) + descriptors = [] + + for descriptor in self._service_descriptors: + if descriptor.lifetime == ServiceLifetimeEnum.singleton: + descriptors.append(descriptor) + else: + descriptors.append(copy.deepcopy(descriptor)) + + sb = ScopeBuilder(ServiceProvider(descriptors, self._configuration, self._database_context)) return sb.build() def get_service(self, service_type: T, *args, **kwargs) -> Optional[T]: diff --git a/tests/custom/general/src/general/appsettings.edrafts-pc-ubuntu.json b/tests/custom/general/src/general/appsettings.edrafts-pc.json similarity index 100% rename from tests/custom/general/src/general/appsettings.edrafts-pc-ubuntu.json rename to tests/custom/general/src/general/appsettings.edrafts-pc.json