DI for injector
Project description
di4injector
DI for Injector
How to use
pip install di4injector
# at example.py
import abc
from di import DIContainer, DI
class GreetingService(abc.ABC):
@abc.abstractmethod
def greeting(self) -> str:
pass
class EnglishGreetingService(GreetingService):
def greeting(self) -> str:
return 'Hello'
class JapaneseGreetingService(GreetingService):
def greeting(self) -> str:
return 'こんにちは'
di = DI.of(
GreetingService, # Abstract class
{ # inject
"JP": JapaneseGreetingService, # DI_PROFILE_ACTIVES=JP,...
"EN": EnglishGreetingService # DI_PROFILE_ACTIVES=EN,...
},
EnglishGreetingService # Default
)
DIContainer.instance().register(di)
greeting_service = DIContainer.instance().resolve(GreetingService)
greeting_service.greeting()
For Developer
run test
pytest -v ./tests
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
di4injector-0.0.2.tar.gz
(2.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file di4injector-0.0.2.tar.gz.
File metadata
- Download URL: di4injector-0.0.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecd897055a75f8f73cbaeca21d6ddfea8d895c0ba5f66ad800ab49948a1e81b4
|
|
| MD5 |
5741aa77ea8bab6d3fca82fb61fa2216
|
|
| BLAKE2b-256 |
f716d4690e7b958f31939270fa583ce03ee5dbfa13f6a7556c7324c911ae8291
|
File details
Details for the file di4injector-0.0.2-py3-none-any.whl.
File metadata
- Download URL: di4injector-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7260f610edc3be305799858d1e4b298001d5d0951d434b577b68e4d75f0c2b65
|
|
| MD5 |
b19fb7332d3b94f361291ff2488f7933
|
|
| BLAKE2b-256 |
817b4347b2aecce89a1b8a3b21401e0a41f2aa895cc52c48678682da96fce1d2
|