Skip to main content

Yet Another Python Dependency Injection

Project description

YAPYDI: Yet Another Python Dependency Injection

Why? Just need a simpler DI, checked some existing ones, not a fun, so developed this one.

Why DI in python? Well, it is NOT for everyone. It is always an good idea for loose coupling for user and implmentation.

How to use it

Install

pip install yapydi

Basic usage

from yapydi import enable_di, bean, injected, Injected

@bean()
def world() -> str:
    return "World"
    
@injected
def hello_world(world : str = Injected[str]):
    print("Hello {}!".format(world))

@enable_di
def main():
    hello_world()

if __name__ == "__main__":
    main()

Advanced usage

from yapydi import enable_di, bean, BeanRegistry

@bean(name="my_bean_name")
def world() -> str:
    return "World"

def hello_world():
    registry = BeanRegistry.get_instance()
    print("Hello {}!".format(registry.one_by_name("my_bean_name")))

@enable_di
def main():
    hello_world()

if __name__ == "__main__":
    main()

Check more details inside * injection_test.py * please.

How does it work

Doing bean definition and injection with annotation power. @bean() annotation will get the bean to be registered. @enable_di will init the beans, and @injected will be hooked so the injection can happen. BeanRegistry is the only place for retrieve beans by name type or both.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yapydi-0.1.3-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

File details

Details for the file yapydi-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: yapydi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 26.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.8

File hashes

Hashes for yapydi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b7cc5058c171f3c0b06d60a1d3dd571c53303e2e32ddc23cbc91fe2e20102b15
MD5 e9ffb04e6e2309512353cc36b1df82ea
BLAKE2b-256 2dc1ac07d747b1eec44525697537dc597a73b07abc4ad0bbbdb0671ac94ed88f

See more details on using hashes here.

Supported by

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