A simple dependency injection library for python.
Project description
py-dependency-injection
This is a simple dependency injection library for python. It provides a simple and flexible way to manage dependencies in your Python applications, promoting modularity, testability, and code maintainability.
Features:
- Dependency Container
- Constructor Injection
- Support Dependency Scopes
Python Compatibility
This library is compatible with the following Python versions:
- Python 3.8
Installation:
$ pip install py-dependency-injection
Example:
from dependency_injection.container.container import DependencyContainer
container = DependencyContainer.get_instance()
# Register dependencies
container.register_transient(SomeInterface, SomeClass)
container.register_scoped(AnotherInterface, AnotherClass)
container.register_singleton(ThirdInterface, ThirdClass)
# Resolve dependencies
transient_instance = container.resolve(SomeInterface)
scoped_instance = container.resolve(AnotherInterface, scope_name="http_request_scope_123")
singleton_instance = container.resolve(ThirdInterface)
# Use dependencies
transient_instance.do_something()
scoped_instance.do_something()
singleton_instance.do_something()
Documentation:
You can find the latest documentation at readthedocs.
Contribution:
If you want to contribute to the code base, create a pull request on the develop branch.
We follow the git flow model, documentation can be found here:
Release Notes
1.0.0-alpha.1 (2024-02-25)
- Initial alpha release.
- Added Dependency Container: The library includes a simple dependency container for managing object dependencies.
- Added Constructor Injection: Users can leverage constructor injection for cleaner and more modular code.
- Added Dependency Scopes: Define and manage the lifecycle of dependencies with support for different scopes.
- Basic Documentation: An initial set of documentation is provided, giving users an introduction to the library.
- License: Released under the GPL 3 license.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for py-dependency-injection-1.0.0a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bfc0fa0da11b55216a7134c7659fc9ff3d909c30159c910d2aa24ea4a0164d3 |
|
MD5 | 211194e1b7d8d1af47b0363e1ac28509 |
|
BLAKE2b-256 | 47cba9e4ca7e6ede624b91ba8b26716feabc47dcc4f85e9ec87dc0a16eb4c6fa |
Close
Hashes for py_dependency_injection-1.0.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f185dcd22818c8e4cd520f7cebf516b89c748452612c01ba8042b60814ab47ba |
|
MD5 | 2fd9ca75b0007c6075e124c23a74ee84 |
|
BLAKE2b-256 | d1422f48ed02418792e0970129ebc087969fb0ccfc76ea32afb4dbd5050a46b4 |