Improved scope handling
This commit is contained in:
parent
55609fc691
commit
88e83db330
@ -9,6 +9,13 @@ class Scope(ScopeABC):
|
||||
def __init__(self, service_provider: ServiceProviderABC):
|
||||
self._service_provider = service_provider
|
||||
self._service_provider.set_scope(self)
|
||||
ScopeABC.__init__(self)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.dispose()
|
||||
|
||||
@property
|
||||
def service_provider(self) -> ServiceProviderABC:
|
||||
|
@ -18,7 +18,7 @@ class ScopeABC(ABC):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def dispose():
|
||||
def dispose(self):
|
||||
r"""Sets service_provider to None
|
||||
"""
|
||||
pass
|
@ -53,4 +53,9 @@ class Application(ApplicationABC):
|
||||
ip_pipe2: IPAddressPipe = self._services.get_service(IPAddressPipe)
|
||||
Console.write_line(f'DI working: {test == test2 and ip_pipe != ip_pipe2}')
|
||||
Console.write_line(self._services.get_service(LoggerABC))
|
||||
|
||||
scope = self._services.create_scope()
|
||||
Console.write_line('scope', scope)
|
||||
with self._services.create_scope() as s:
|
||||
Console.write_line('with scope', s)
|
||||
# self.test_send_mail()
|
||||
|
Loading…
Reference in New Issue
Block a user