-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45f52bf
commit 76b8661
Showing
15 changed files
with
215 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,32 @@ | ||
|
||
|
||
from fastapi import FastAPI | ||
from fastapi_hive.ioc_framework.endpoint_model import Endpoint, EndpointAsync | ||
from demo.yyy_endpoint.house_price2.router import router | ||
from demo.yyy_endpoint.house_price2.service import service | ||
|
||
|
||
class EndpointImpl(Endpoint): | ||
|
||
def __init__(self, app: FastAPI): | ||
super(EndpointImpl, self).__init__(app) | ||
|
||
def setup(self): | ||
print("call pre setup from EndpointImpl!!!") | ||
print("---- get fastapi app ------") | ||
print(self._app) | ||
|
||
def teardown(self): | ||
print("call pre teardown from EndpointImpl!!!") | ||
|
||
|
||
class EndpointAsyncImpl(EndpointAsync): | ||
|
||
def __init__(self, app: FastAPI): | ||
super(EndpointAsyncImpl, self).__init__(app) | ||
|
||
async def setup(self): | ||
print("call pre setup from cornerstone EndpointAsyncImpl!!!") | ||
|
||
async def teardown(self): | ||
print("call pre teardown from cornerstone EndpointAsyncImpl!!!") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
from fastapi_hive.ioc_framework.endpoint_hook_caller.implement import EndpointHookCaller, EndpointHookAsyncCaller | ||
|
||
|
||
__all__ = ["EndpointHookCaller", "EndpointHookAsyncCaller"] |
93 changes: 93 additions & 0 deletions
93
fastapi_hive/ioc_framework/endpoint_hook_caller/implement.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
|
||
from fastapi import FastAPI | ||
from loguru import logger | ||
from fastapi_hive.ioc_framework.endpoint_container import EndpointContainer | ||
from fastapi_hive.ioc_framework.endpoint_model import Endpoint, EndpointAsync, EndpointMeta | ||
from dependency_injector.wiring import Provide, inject | ||
from fastapi_hive.ioc_framework.di_contiainer import DIContainer | ||
from fastapi_hive.ioc_framework.ioc_config import IoCConfig | ||
|
||
|
||
class EndpointHookCaller: | ||
@inject | ||
def __init__( | ||
self, | ||
app: FastAPI, | ||
endpoint_container: EndpointContainer = Provide[DIContainer.endpoint_container], | ||
ioc_config: IoCConfig = Provide[DIContainer.ioc_config], | ||
): | ||
logger.info("endpoint hook caller is starting.") | ||
|
||
self._app = app | ||
self._endpoint_container = endpoint_container | ||
self._ioc_config = ioc_config | ||
|
||
def run_setup_hook(self): | ||
|
||
modules = self._endpoint_container.modules | ||
for one_module, one_entity in modules.items(): | ||
one_entity: EndpointMeta = one_entity | ||
imported_module = one_entity.imported_module | ||
|
||
if not hasattr(imported_module, 'EndpointImpl'): | ||
continue | ||
|
||
endpoint: Endpoint = imported_module.EndpointImpl(self._app) | ||
|
||
endpoint.setup() | ||
|
||
def run_teardown_hook(self): | ||
modules = self._endpoint_container.modules | ||
for one_module, one_entity in modules.items(): | ||
one_entity: EndpointMeta = one_entity | ||
imported_module = one_entity.imported_module | ||
|
||
if not hasattr(imported_module, 'EndpointImpl'): | ||
continue | ||
|
||
cornerstone: Endpoint = imported_module.EndpointImpl(self._app) | ||
|
||
cornerstone.teardown() | ||
|
||
|
||
class EndpointHookAsyncCaller: | ||
@inject | ||
def __init__( | ||
self, | ||
app: FastAPI, | ||
endpoint_container: EndpointContainer = Provide[DIContainer.endpoint_container], | ||
ioc_config: IoCConfig = Provide[DIContainer.ioc_config], | ||
): | ||
logger.info("endpoint hook async caller is starting.") | ||
|
||
self._app = app | ||
self._endpoint_container = endpoint_container | ||
self._ioc_config = ioc_config | ||
|
||
async def run_setup_hook(self): | ||
modules = self._endpoint_container.modules | ||
for one_module, one_entity in modules.items(): | ||
one_entity: EndpointMeta = one_entity | ||
imported_module = one_entity.imported_module | ||
|
||
if not hasattr(imported_module, 'EndpointAsyncImpl'): | ||
continue | ||
|
||
endpoint: EndpointAsync = imported_module.EndpointAsyncImpl(self._app) | ||
|
||
await endpoint.setup() | ||
|
||
async def run_teardown_hook(self): | ||
modules = self._endpoint_container.modules | ||
for one_module, one_entity in modules.items(): | ||
one_entity: EndpointMeta = one_entity | ||
imported_module = one_entity.imported_module | ||
|
||
if not hasattr(imported_module, 'EndpointAsyncImpl'): | ||
continue | ||
|
||
endpoint: EndpointAsync = imported_module.EndpointAsyncImpl(self._app) | ||
|
||
await endpoint.teardown() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
|
||
from fastapi_hive.ioc_framework.endpoint_model.implement import Endpoint | ||
from fastapi_hive.ioc_framework.endpoint_model.implement import EndpointMeta, Endpoint, EndpointAsync | ||
|
||
|
||
__all__ = ["Endpoint"] | ||
__all__ = ["EndpointMeta", "Endpoint", "EndpointAsync"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters