Skip to content

Commit 939fd1b

Browse files
committed
Moved core Module to core packaage and to control app events with it
1 parent b03124f commit 939fd1b

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed
Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from ellar.common import (
66
GlobalGuard,
77
GuardCanActivate,
8-
IApplicationReady,
98
IApplicationShutdown,
109
IApplicationStartup,
1110
IExceptionMiddlewareService,
@@ -20,11 +19,14 @@
2019
IWebSocketContextFactory,
2120
Module,
2221
)
23-
from ellar.core import ModuleSetup
22+
from ellar.common.interfaces import ITemplateRenderingService
23+
from ellar.common.logging import logger
24+
from ellar.core import ModuleSetup, TemplateRenderingService
2425
from ellar.core.conf import Config
2526
from ellar.core.exceptions.service import ExceptionMiddlewareService
26-
from ellar.core.execution_context import ExecutionContextFactory, HostContextFactory
2727
from ellar.core.execution_context.factory import (
28+
ExecutionContextFactory,
29+
HostContextFactory,
2830
HTTPConnectionContextFactory,
2931
WebSocketContextFactory,
3032
)
@@ -33,6 +35,7 @@
3335
from ellar.core.services import Reflector, reflector
3436
from ellar.di import EllarInjector, ProviderConfig, injectable, request_scope
3537
from ellar.di.injector.tree_manager import ModuleTreeManager
38+
from ellar.events import app_context_started, app_context_teardown
3639

3740
if t.TYPE_CHECKING: # pragma: no cover
3841
from ellar.app import App
@@ -64,6 +67,11 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
6467
use_class=GlobalCanActivatePlaceHolder,
6568
export=True,
6669
),
70+
ProviderConfig(
71+
ITemplateRenderingService,
72+
use_class=TemplateRenderingService,
73+
export=True,
74+
),
6775
ProviderConfig(
6876
ModuleTreeManager,
6977
use_value=lambda: config.MODULE_TREE_MANAGER_CLASS(
@@ -118,18 +126,23 @@ def get_core_module(app_module: t.Union[t.Type, t.Any], config: Config) -> t.Typ
118126
),
119127
],
120128
)
121-
class EllarCoreModule(IApplicationReady, IApplicationStartup, IApplicationShutdown):
129+
class EllarCoreModule(IApplicationStartup, IApplicationShutdown):
122130
def __init__(self, _config: Config, injector: EllarInjector) -> None:
123131
self.config = _config
124132
self.injector = injector
125133

126-
def on_ready(self, app: "App") -> None:
127-
pass
128-
129134
async def on_startup(self, app: "App") -> None:
130-
pass
135+
try:
136+
await app_context_started.run(app=app)
137+
except Exception as ex: # pragma: no cover
138+
logger.exception(ex)
139+
raise ex
131140

132141
async def on_shutdown(self) -> None:
133-
pass
142+
try:
143+
await app_context_teardown.run()
144+
except Exception as ex: # pragma: no cover
145+
logger.exception(ex)
146+
raise ex
134147

135148
return EllarCoreModule

0 commit comments

Comments
 (0)