Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
diwire: type-driven dependency injection for Python
diwire: type-driven dependency injection for Python
v1.3.1 GitHub

Learn

  • Quick start (FastAPI)
  • Dependency injection (DI)
  • Learning paths
  • Why diwire
  • Tutorial (runnable examples)
    • Quickstart
    • Registration methods
    • Autoregistration
    • Lifetimes
    • Scopes & cleanup
    • Scope context values
    • Function injection
    • Named components
    • Annotation normalization
    • Providers
    • Compilation
    • Open generics
    • ResolverContext
    • Lock modes
    • Async
    • Errors & troubleshooting
    • Resolve all components
    • Maybe
    • Supported frameworks
    • Pydantic settings
    • Pytest plugin
    • FastAPI
  • Core concepts
    • Container
    • Registration
    • Lifetimes
    • Scopes & cleanup
    • Function injection
    • Components (named registrations)
    • Open generics
    • Async
    • resolver_context
    • Compilation
    • Errors
    • Integrations
  • How-to guides
    • Web frameworks
      • FastAPI
      • Litestar
      • aiohttp
      • Celery
      • Starlette (and other ASGI frameworks)
      • Flask (WSGI)
      • Django
      • django-modern-rest
    • Testing
      • Overrides
      • pytest
    • Patterns
      • Request scope
      • Unit of work
      • Resources (cleanup)
      • Decorators
      • Interfaces (Protocol/ABC)
      • Handler classes (methods)
    • Advanced
      • Auto-registration tuning
      • Performance
      • Concurrency
  • API reference
    • Container
    • ResolverContext
    • resolver_context
    • Types
    • Exceptions
Back to top
View this page
Edit this page

Handler classes (methods)¶

For controller/handler classes, you often want DI on instance methods (not just free functions).

Use diwire.ResolverContext.inject() (via diwire.resolver_context) on methods to create injected callables that still behave like methods.

Example (runnable)¶

See ResolverContext.

Next
Advanced
Previous
Interfaces (Protocol/ABC)
Copyright ©
Made with Sphinx and @pradyunsg's Furo
On this page
  • Handler classes (methods)
    • Example (runnable)