Skip to main content

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


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)

Uploaded Source

Built Distribution

di4injector-0.0.1-py3-none-any.whl (2.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page