Improved service providing and app hosting

This commit is contained in:
2020-11-26 19:17:05 +01:00
parent c6d1dce577
commit 7d4efe7bda
9 changed files with 97 additions and 19 deletions

View File

@@ -18,7 +18,7 @@ class ServiceProviderBase(ServiceBase):
def add_scoped(self, service_type: Type[ServiceBase], service: Type[ServiceBase]): pass
@abstractmethod
def add_singleton(self, service_type: Type[ServiceBase], service: ServiceBase): pass
def add_singleton(self, service_type: Type[ServiceBase], service: Callable[ServiceBase]): pass
@abstractmethod
def get_service(self, instance_type: Type[ServiceBase]) -> Callable[ServiceBase]: pass

View File

@@ -43,7 +43,7 @@ class ServiceProvider(ServiceProviderBase):
def add_scoped(self, service_type: Type[ServiceBase], service: Type[ServiceBase]):
self._scoped_services[service_type] = service
def add_singleton(self, service_type: Type[ServiceBase], service: ServiceBase):
def add_singleton(self, service_type: Type[ServiceBase], service: Callable[ServiceBase]):
for known_service in self._singleton_services:
if type(known_service) == type(service_type):
raise Exception(f'Service with type {type(service_type)} already exists')