Django Ninja support
Opened this issue · 1 comments
devjerry0 commented
Anyone else trying to di with django ninja?
Would love some examples on y'alls implementations.
Atm I have been adding it under the main project next to asgi and added asynccontext with lifespan.
AndrianEquestrian commented
Hi! It seems that Ninja, does not have the way to make Pydantic ignore dependency injections by default.
As far as I can tell, You have already raised an issue for Ninja received several answer that seems to contain a solution.
P.s. Everything should be working outside of request handlers. In case if solutions proposed by Ninja won't work or you don't want to install additional dependencies, refer example below:
api = NinjaAPI()
class HelloResponseSchema(Schema):
message: str
@inject
def nested_hello(request, ats: AnnotatedTestService = Provide["ats"]) -> HelloResponseSchema:
return HelloResponseSchema(message=ats())
@api.get("/hello", response=HelloResponseSchema)
def hello(request) -> HelloResponseSchema:
return nested_hello(request)