disl: super lightweight (only 35 lines) dependency injection (ioc) support for Python
A super simple and risk-free way to do dependency injection (ioc) in Python. The entire code base is only 35 lines (empty lines included). No need to use a complex 3rd-party framework or be concerned about the long-term viability of the library.
How to use
Suppose you have a module to read some products' info from a DB file, so the path to the DB file should be injected:
from disl import Inject
class ProductDb:
def __init__(self):
self.db_path=Inject() # this variable will be set automatically
def get_products(self):
print(f"getting products from {self.db_path}")
In your main program, you link up the ProductDb object and the db_path:
from disl import Disl
di=Disl() # this is the container
di.add_raw_bean("pdb", ProductDb()) # add the bean under the name "pdb"
di.add_raw_bean("db_path", "c:/Users/kent/test.db") # another bean
pdb=di.get_wired_bean("pdb") # the db_path field in the pdb bean will be set
pdb.get_products() # this pdb object is just the plain object you created
If the path to the DB is named "database_path" but your variable name is just "db_path", you can do it like this:
from disl import Inject
class ProductDb:
def __init__(self):
self.db_path=Inject("database_path") # specify the bean name
def get_products(self):
print(f"getting products from {self.db_path}")
from disl import Disl
di=Disl()
di.add_raw_bean("pdb", ProductDb())
di.add_raw_bean("database_path", "c:/Users/kent/test.db")
pdb=di.get_wired_bean("pdb")
pdb.get_products()
Metadata
Release files for disl 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| disl-0.0.4.tar.gz | 6.7 kB | Without provenance | Details for disl-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| disl-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for disl-0.0.4-py3-none-any.whl |
Total release size: 14.0 kB
Release files / disl-0.0.4.tar.gz
| Download URL | disl-0.0.4.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
312e8f6167eabcb3d112ed85bac2d86c219cfabc6c2cbaf88adf5a06854b4aca
|
|
BLAKE2b-256 checksum How to use checksums |
458945184d132f007316ace9614097814a0d565373f88240b8dc3ad136fe53b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / disl-0.0.4-py3-none-any.whl
| Download URL | disl-0.0.4-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b59eb7b7856c461bd40fd53376249011eb30a42c9d6f09bdaa6ef47c9ae4d4bc
|
|
BLAKE2b-256 checksum How to use checksums |
e7231fffc919adec5d5a5aaaa3fe4350a6ae12536306079e94ff6ba97d1f49db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for disl 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.