injector package¶
injector.dependencies module¶
- class injector.dependencies.Dependencies[source]¶
Bases: builtins.object
A factory for setting up and building an Injector instance.
- build_injector()[source]¶
Builds an injector instance that can be used to inject dependencies.
Also checks for common errors (missing dependencies and circular dependencies).
Returns: Injector
- register_factory(name, factory, dependencies=None)[source]¶
Binds a factory to a name. The injector will call the factory function once (if the name is ever used), and always return the value that the factory returns.
The factory will be called with the dependencies (if any listed) as arguments.
Parameters: - name – A string naming the dependency (e.g. ‘db-connection’)
- factory – A factory function to create the dependency
- dependencies – (optional) A list of dependencies of the factory function
injector.exceptions module¶
- exception injector.exceptions.BadNameException[source]¶
Bases: injector.exceptions.InjectorException
Raised when an invalid name is used
- exception injector.exceptions.CircularDependencyException[source]¶
Bases: injector.exceptions.InjectorException
Raised when the dependencies defined are circular
- exception injector.exceptions.DuplicateNameException[source]¶
Bases: injector.exceptions.InjectorException
Raised when a duplicate name is used
- exception injector.exceptions.InjectorException[source]¶
Bases: builtins.Exception
Base class for exceptions raised by the injector
- exception injector.exceptions.MissingDependencyException[source]¶
Bases: injector.exceptions.InjectorException
Raised when a requested dependency is not found
injector.graph module¶
injector.injector module¶
- class injector.injector.Injector(factories)[source]¶
Bases: builtins.object
An injector filled with dependencies, ready to inject.
- get_dependency(name)[source]¶
Get the value of a dependency.
Parameters: name – The name of the dependency Returns: the value of the dependency