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 'こんにちは'
DIContainer.instance().register(DI.of(
GreetingService, # Abstract class
{ # inject
"JP": JapaneseGreetingService, # DI_PROFILE_ACTIVES=JP,...
"EN": EnglishGreetingService # DI_PROFILE_ACTIVES=EN,...
},
EnglishGreetingService # Default
))
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.1.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for di4injector-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ce81a1d7a3458f5a7713e488e66661e30617d5a78becb2b204be055b4836bdd |
|
MD5 | ec7a1d7d80677dca63d64bdfba80aded |
|
BLAKE2b-256 | 80b9e6aa69cb968171435f69ba76b036180cfe25ec8751e26da8116d952912b4 |