Skip to content

Django Integration

  • Inject Beyond Views


    Inject in core Django views, DRF handlers, Ninja endpoints, middleware helpers, decorators, and other request-time call sites.

    Learn more

  • App-Level Entry Points


    Use @inject_app for management commands, Django 6 background tasks, signals, checks, and scripts outside request scope.

    Learn more

  • Request Context in Services


    Inject HttpRequest and other scoped services into your application code without threading request objects through every layer.

    Learn more

  • Django, DRF, and Ninja


    Use one DI model across core Django, Django REST framework, and Django Ninja while keeping your service layer framework-agnostic.

Wireup integrates with Django at both request scope and application scope. Use @inject for request-time callables and @inject_app for non-request entry points, while keeping services as ordinary Python classes that are easy to test and reuse.

Quick Start

This is the shortest path to a working endpoint with explicit injection.

settings.py
from wireup.integration.django import WireupSettings

INSTALLED_APPS = [
    # ...existing apps...
    "wireup.integration.django",
]

MIDDLEWARE = [
    "wireup.integration.django.wireup_middleware",
    # ...existing middleware...
]

WIREUP = WireupSettings(
    injectables=["mysite.services"],
    auto_inject_views=False,
)
mysite/services.py
from wireup import injectable


@injectable
class GreeterService:
    def greet(self, name: str) -> str:
        return f"Hello {name}"
mysite/views.py
from django.http import HttpRequest, HttpResponse
from wireup import Injected
from wireup.integration.django import inject

from mysite.services import GreeterService


@inject
def greet(
    request: HttpRequest, greeter: Injected[GreeterService]
) -> HttpResponse:
    return HttpResponse(greeter.greet(request.GET.get("name", "World")))
mysite/urls.py
from django.urls import path

from mysite.views import greet

urlpatterns = [
    path("greet/", greet),
]

Run the app with python manage.py runserver, then open http://127.0.0.1:8000/greet/?name=World.

Detailed Guides

API Reference