Made startup/app extensions static
This commit is contained in:
@@ -4,8 +4,7 @@ from cpl.dependency import ServiceProviderABC
|
||||
|
||||
|
||||
class ApplicationExtensionABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self): ...
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def run(self, services: ServiceProviderABC): ...
|
||||
def run(services: ServiceProviderABC): ...
|
||||
|
||||
@@ -6,15 +6,14 @@ from cpl.dependency.service_collection import ServiceCollection
|
||||
class StartupABC(ABC):
|
||||
r"""ABC for the startup class"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def __init__(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def configure_configuration(self):
|
||||
def configure_configuration():
|
||||
r"""Creates configuration of application"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def configure_services(self, service: ServiceCollection):
|
||||
def configure_services(service: ServiceCollection):
|
||||
r"""Creates service provider
|
||||
|
||||
Parameter:
|
||||
|
||||
@@ -6,15 +6,14 @@ from cpl.dependency import ServiceCollection
|
||||
class StartupExtensionABC(ABC):
|
||||
r"""ABC for startup extension classes"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def __init__(self): ...
|
||||
|
||||
@abstractmethod
|
||||
def configure_configuration(self):
|
||||
def configure_configuration():
|
||||
r"""Creates configuration of application"""
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def configure_services(self, services: ServiceCollection):
|
||||
def configure_services(services: ServiceCollection):
|
||||
r"""Creates service provider
|
||||
Parameter:
|
||||
services: :class:`cpl.dependency.service_collection`
|
||||
|
||||
@@ -35,7 +35,7 @@ class ApplicationBuilder:
|
||||
return self._services.build()
|
||||
|
||||
def use_startup(self, startup: Type[StartupABC]) -> "ApplicationBuilder":
|
||||
self._startup = startup()
|
||||
self._startup = startup
|
||||
return self
|
||||
|
||||
def use_extension(
|
||||
@@ -50,8 +50,7 @@ class ApplicationBuilder:
|
||||
return self
|
||||
|
||||
def build(self) -> ApplicationABC:
|
||||
for ex in self._startup_extensions:
|
||||
extension = ex()
|
||||
for extension in self._startup_extensions:
|
||||
Host.run(extension.configure_configuration)
|
||||
Host.run(extension.configure_services, self._services)
|
||||
|
||||
@@ -59,8 +58,7 @@ class ApplicationBuilder:
|
||||
Host.run(self._startup.configure_configuration)
|
||||
Host.run(self._startup.configure_services, self._services)
|
||||
|
||||
for ex in self._app_extensions:
|
||||
extension = ex()
|
||||
for extension in self._app_extensions:
|
||||
Host.run(extension.run, self.service_provider)
|
||||
|
||||
return self._app(self.service_provider)
|
||||
|
||||
Reference in New Issue
Block a user