Skip to content

Commit 8233bf9

Browse files
committed
controller instance global
1 parent 26e976c commit 8233bf9

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

fastapi_router_controller/lib/controller.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from fastapi import APIRouter
22

33
OPEN_API_TAGS = []
4-
__app_classes__ = []
4+
__app_controllers__ = []
55
__router_params__ = [
66
'response_model',
77
'status_code',
@@ -67,7 +67,7 @@ def wrapper(cls):
6767
self.__get_parent_routes(cls.__router__)
6868

6969
cls.__router__ = self.router
70-
cls.router = lambda _: Controller.__parse_controller_router(cls)
70+
cls.router = lambda it_self: Controller.__parse_controller_router(it_self)
7171
return cls
7272

7373
return wrapper
@@ -77,7 +77,7 @@ def use(_):
7777
A decorator function to mark a Class to be automatically loaded by the Controller
7878
'''
7979
def wrapper(cls):
80-
__app_classes__.append(cls)
80+
__app_controllers__.append(cls())
8181
return cls
8282

8383
return wrapper
@@ -101,10 +101,9 @@ def routers():
101101
'''
102102
routers = []
103103

104-
for app_class in __app_classes__:
105-
controller = app_class()
104+
for app_controller in __app_controllers__:
106105
routers.append(
107-
controller.router()
106+
app_controller.router()
108107
)
109108

110109
return routers

0 commit comments

Comments
 (0)