Skip to content

Commit 9dc17fe

Browse files
Merge pull request #166 from nexios-labs/dev
Fix(internals): now only inject depency once and just pass wrap handlers directly
2 parents e1d263e + 53bccf8 commit 9dc17fe

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

nexios/dependencies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ def __init__(
4242
"current_context"
4343
)
4444

45+
test_var = 1
46+
4547

4648
def inject_dependencies(handler: Callable[..., Any]) -> Callable[..., Any]:
4749
"""Decorator to inject dependencies into a route handler while preserving parameter names and passing context if needed."""
4850

4951
@wraps(handler)
5052
async def wrapped(*args: List[Any], **kwargs: Dict[str, Any]) -> Any:
53+
global test_var
54+
test_var += 1
5155
sig = signature(handler)
5256
bound_args = sig.bind_partial(*args, **kwargs)
5357
params = list(sig.parameters.values())

nexios/routing/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import warnings
44
from abc import ABC, abstractmethod
5-
from typing import Any, Dict, List, Optional
5+
from typing import Any, Dict, List, Optional, Type
66

77
from nexios.types import ASGIApp, Receive, Scope, Send
88

@@ -15,7 +15,7 @@ class BaseRouter(ABC):
1515

1616
def __init__(self, prefix: Optional[str] = None):
1717
self.prefix = prefix or ""
18-
self.routes: List[Any] = []
18+
self.routes: List[Type[BaseRoute]] = []
1919
self.middleware: List[Any] = []
2020
self.sub_routers: Dict[str, ASGIApp] = {}
2121

nexios/routing/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from nexios.openapi import Parameter
3838
from nexios.structs import RouteParam, URLPath
3939
from nexios.types import ASGIApp, HandlerType, MiddlewareType, Receive, Scope, Send
40+
4041
from ._utils import get_route_path
4142
from .base import BaseRoute, BaseRouter
4243

@@ -559,7 +560,7 @@ async def wrapped_handler(
559560

560561
return await original_handler(*handler_args, **handler_kwargs)
561562

562-
route.handler = inject_dependencies(wrapped_handler)
563+
route.handler = wrapped_handler
563564

564565
self.routes.append(route)
565566

0 commit comments

Comments
 (0)