Fixed scoped #148

This commit is contained in:
Sven Heidemann 2022-12-20 14:50:35 +01:00
parent 2fb515195c
commit c09f2f8e83
3 changed files with 18 additions and 18 deletions

View File

@ -93,7 +93,7 @@ class ServiceProvider(ServiceProviderABC):
self._scope = scope self._scope = scope
def create_scope(self) -> ScopeABC: 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() return sb.build()
def get_service(self, service_type: type) -> Optional[object]: def get_service(self, service_type: type) -> Optional[object]:

View File

@ -20,25 +20,22 @@ class Application(ApplicationABC):
pass pass
def main(self): def main(self):
with self._services.create_scope() as scope:
Console.write_line('Scope1') Console.write_line('Scope1')
scope1: Scope = self._services.create_scope() ts: TestService = scope.service_provider.get_service(TestService)
ts: TestService = scope1.service_provider.get_service(TestService)
ts.run() ts.run()
dit: DITesterService = scope1.service_provider.get_service(DITesterService) dit: DITesterService = scope.service_provider.get_service(DITesterService)
dit.run() dit.run()
t = scope1
b = t.service_provider
scope1.dispose()
#Console.write_line('Disposed:') #Console.write_line('Disposed:')
#ts1: TestService = scope1.service_provider.get_service(TestService) #ts1: TestService = scope1.service_provider.get_service(TestService)
#ts1.run() #ts1.run()
with self._services.create_scope() as scope:
Console.write_line('Scope2') Console.write_line('Scope2')
scope2: Scope = self._services.create_scope() ts: TestService = scope.service_provider.get_service(TestService)
ts: TestService = scope2.service_provider.get_service(TestService)
ts.run() ts.run()
dit: DITesterService = scope2.service_provider.get_service(DITesterService) dit: DITesterService = scope.service_provider.get_service(DITesterService)
dit.run() dit.run()
Console.write_line('Global') Console.write_line('Global')

View File

@ -16,7 +16,10 @@
"LicenseName": "", "LicenseName": "",
"LicenseDescription": "", "LicenseDescription": "",
"Dependencies": [ "Dependencies": [
"sh_cpl>=2021.10.0.post1" "cpl-core==2022.12.0"
],
"DevDependencies": [
"cpl-cli==2022.12.0"
], ],
"PythonVersion": ">=3.9.2", "PythonVersion": ">=3.9.2",
"PythonPath": {}, "PythonPath": {},