Dependency Injection for Humans™
Injectable: Dependency Injection for Humans™
Injectable is an elegant and simple Dependency Injection framework built with Heart and designed for Humans.
from injectable import Autowired, autowired from typing import List from models import Database from messaging import Broker class Service: @autowired def __init__( self, database: Autowired(Database), message_brokers: Autowired(List[Broker]), ): pending = database.get_pending_messages() for broker in message_brokers: broker.send_pending(pending)
from abc import ABC class Broker(ABC): def send_pending(messages): ...
from injectable import injectable @injectable class Database: ...
from messaging import Broker from injectable import injectable @injectable class KafkaProducer(Broker): ...
from messaging import Broker from injectable import injectable @injectable class SQSProducer(Broker): ...
Features you’ll love ❤️
- Autowiring: injection is transparent to the function. Just decorate the function
@autowiredand annotate parameters with
Autowired, that’s it.
- Automatic dependency discovery: just call
load_injection_container()at the root of your project or pass the root path as an argument. All classes decorated with
@injectablewill be automatically discovered and ready for injection.
- Qualifier overloading: declare as many injectables as you like for a single
qualifier or extending the same base class. You can inject all of them just by
- Transparent lazy initialization: passing the argument
Autowiredwill make your dependency to be initialized only when actually used, all in a transparent fashion.
- Singletons: decorate your class with
@injectable(singleton=True)and only a single instance will be initialized and shared for injection.
- Namespaces: specify different namespaces for injectables as in
@injectable(namespace="foo")and then just use them when annotating your parameters as in
dep: Autowired(..., namespace="foo").
- Linters friendly:
Autowiredis carefully designed to comply with static linter analysis such as PyCharm’s to preserve the parameter original type hint.
These are just a few cool and carefully built features for you. Check out our docs!
- Fix injectable crashing when relative imports are used in files containing injectables.
- Fix testing.register_injectables not creating the namespace when it doesn’t exist yet
- Fix opening of UTF-8 files & allow for user set encoding
- Fix inject return type hint
- Fix Injectable failing to resolve complex/entangled imports
- Fix optional injection bug when the namespace is empty
- Fix the use of named args by the caller breaking autowired functions injection
- Deprecate InjectionContainer::load in favor of load_injection_container.
- Change default namespace name from "_GLOBAL" to "DEFAULT_NAMESPACE".
- Fix minor quirks with Python 3.7 and 3.8.
- Add tons of unit tests.
- Add reset_injection_container utility to injectable.testing.
- Include the injectable.testing utilities to ease mocking injectables.
- InjectionContainer::load is more resilient against duplicated injectables registering
- Support for optional injection in declarative fashion: Autowired(Optional[...])
- Fix Autowired(List[...]) not working with qualifiers
- Fix Windows injectables not being loaded.
- Remove unused inspect imports.
- Fix bug of scanning the same module more than once when InjectionContainer.load() is called multiple times with different relative search paths.
- Added @injectable_factory decorator for declaring injectable factory methods
- Include the console output in the examples
- Fix package content missing
- Drop support for autowiring without previous initialization of the InjectionContainer
- Refactor @autowired decorator for working with the Autowired type annotation
- Added @injectable decorator for registering injectables to the InjectionContainer
- Support for qualifiers, groups and namespaces
- Added Autowired type annotation for marking parameters for autowiring
- Added inject and inject_multiple as service locators
- Added InjectionContainer for registering injectables
- Official support for Python 3.7 and 3.8
- Official support for Ubuntu, Windows and MacOS
- Drop Python 3.4 and 3.5 official support
- General code refactoring
- Official documentation
- Added usage examples
- Drop Python 3.3 official support
- Support for dependencies of classes without signature
- Fix bug of builtin types not being accepted for injectable dependencies
- Statically infer dependency’s constructor suitability for injection instead of using trial instantiation
- Fix bug of raising TypeError when injectable fails on the trial dependency instantiation which can happen when the dependency does provide a default constructor with no arguments but the running environment (possibly a test suite environment) will make the instantiation fail
- Enable the use of @autowired decorator without parenthesis
- Fixes required dependency lazy_object_proxy not being installed when installing injectable through pip
- First stable release
- Support for lazy dependency initialization
- Support for type annotations with strings
- Python 3.3 and 3.4 support
- First beta release
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size injectable-3.4.7.tar.gz (27.2 kB)||File type Source||Python version None||Upload date||Hashes View|
|Filename, size injectable-3.4.7-py3-none-any.whl (47.0 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
Hashes for injectable-3.4.7-py3-none-any.whl