Gluer
Dependency Injection for Python
Installation
Gluer uses type annotations, so python 3.6+ is required
python3 -m pip install --user gluer
Usage
Let's follow a wonderful explanation of DI:
from abc import ABC, abstractmethod
from gluer import Gluer
class Drink(ABC): # this doesn't *have* to be abstract
@abstractmethod
def sip(self):
pass
class Child:
def __init__(self, drink: Drink):
self.drink = drink
def take_a_sip(self):
self.drink.sip()
print("ahhh")
class Juice(Drink):
def sip(self):
print("*gulp*")
class Coke(Drink):
def sip(self):
print("*fizzle*")
if __name__ == "__main__":
gluer = Gluer()
mom_watches = True
gluer.register(Child)
gluer.register(Juice if mom_watches else Coke).As(Drink)
container = gluer.build()
kid = container.resolve(Child)
kid.take_a_sip() # *gulp* ahhh
Metadata
Release files for gluer 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gluer-0.2.0.tar.gz | 3.6 kB | Details |
Release files / gluer-0.2.0.tar.gz
| Download URL | gluer-0.2.0.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6492e1bd54befac2d7f8dd453e83b314ade314b139aad30f3fb642979813d25d
|
|
BLAKE2b-256 checksum How to use checksums |
a89453db582549eac9d3b547c2da5024b664f5f8c825e4da0141c33ad0ee8e61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6
|