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
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]:

View File

@ -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()

View File

@ -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": {},