lightbulb.di

exception CircularDependencyException[source]

Exception raised when a circular dependency is detected.

exception ContainerClosedException[source]

Exception raised when attempting to get a dependency from a closed container.

exception DependencyInjectionException[source]

Base class for all exceptions raised from the dependency injection system.

exception DependencyNotSatisfiableException[source]

Exception raised when a dependency is requested but cannot be created.

final class AutocompleteContainer(registry: registry_.Registry, *, parent: Container | None = None, tag: Context | None = None)[source]

Injectable type representing the dependency container for the autocomplete context.

final class CommandContainer(registry: registry_.Registry, *, parent: Container | None = None, tag: Context | None = None)[source]

Injectable type representing the dependency container for the command context.

final class Contexts[source]

Collection of the dependency injection context values Lightbulb uses.

AUTOCOMPLETE = 'lightbulb.di.contexts.autocomplete'

DI context used during autocomplete invocation.

COMMAND = 'lightbulb.di.contexts.command'

DI context used during command invocation, including for hooks and error handlers.

DEFAULT = 'linkd.contexts.root'

The base DI context - all other contexts are built with this as the parent.

LISTENER = 'lightbulb.di.contexts.listener'

DI context used during listener invocation.

TASK = 'lightbulb.di.contexts.task'

DI context used during task invocation.

DefaultContainer

alias of RootContainer

If

alias of _If

final class ListenerContainer(registry: registry_.Registry, *, parent: Container | None = None, tag: Context | None = None)[source]

Injectable type representing the dependency container for the listener context.

final class TaskContainer(registry: registry_.Registry, *, parent: Container | None = None, tag: Context | None = None)[source]

Injectable type representing the dependency container for the task context.

Try

alias of _Try

with_di(func: Callable[..., t.Any]) Callable[..., t.Any]

Decorator that enables dependency injection on the decorated function. If dependency injection has been disabled globally then this function does nothing and simply returns the object that was passed in.

Parameters:

func – The function to enable dependency injection for.

Returns:

The function with dependency injection enabled, or the same function if DI has been disabled globally.

Warning

Dependency injection relies on a context being available when the function is called. Refer to library documentation for which flows will have a dependency injection context set-up for you automatically. Otherwise, you will have to set up the context yourself using the helper context manager enter_context().