Replies: 2 comments 10 replies
-
|
@remimd what would you put to Depends ? |
Beta Was this translation helpful? Give feedback.
9 replies
-
|
A bit of a shameless self-promotion here, but @remimd If you're still looking for Dependency Injection in Django Ninja, you might want to check out wireup. It has a Django integration that lets you inject services directly into your views using type hints. from ninja import Router, Schema
from wireup import Injected
from wireup.integration.django import inject
router = Router()
@router.get("/items")
@inject
def list_items(request, s3_manager: Injected[S3Manager]):
# s3_manager is fully wired with its own dependencies
return s3_manager.list_objects()
@router.post("/items")
@inject
def create_item(request, payload: ItemSchema, s3_manager: Injected[S3Manager]):
s3_manager.upload(payload.dict())
return {"success": True} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Usually I work with FastAPI but I recently started a new personal project with django-ninja because I needed an administration interface quickly.
I quickly realized that I was missing an equivalent to
fastapi.Dependswhich is a very efficient tool for factoring code.I think it would also be a good entry point to facilitate library integration into django-ninja.
I wanted to know if I'd missed anything in the documentation or if there were strategies I didn't know about to achieve this.
I'm curious to hear your opinion on this.
Beta Was this translation helpful? Give feedback.
All reactions