Skip to content

Commit

Permalink
controller instance global
Browse files Browse the repository at this point in the history
  • Loading branch information
KiraPC committed Feb 12, 2021
1 parent 26e976c commit 8233bf9
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions fastapi_router_controller/lib/controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import APIRouter

OPEN_API_TAGS = []
__app_classes__ = []
__app_controllers__ = []
__router_params__ = [
'response_model',
'status_code',
Expand Down Expand Up @@ -67,7 +67,7 @@ def wrapper(cls):
self.__get_parent_routes(cls.__router__)

cls.__router__ = self.router
cls.router = lambda _: Controller.__parse_controller_router(cls)
cls.router = lambda it_self: Controller.__parse_controller_router(it_self)
return cls

return wrapper
Expand All @@ -77,7 +77,7 @@ def use(_):
A decorator function to mark a Class to be automatically loaded by the Controller
'''
def wrapper(cls):
__app_classes__.append(cls)
__app_controllers__.append(cls())
return cls

return wrapper
Expand All @@ -101,10 +101,9 @@ def routers():
'''
routers = []

for app_class in __app_classes__:
controller = app_class()
for app_controller in __app_controllers__:
routers.append(
controller.router()
app_controller.router()
)

return routers
Expand Down

0 comments on commit 8233bf9

Please sign in to comment.