Dependency ~~injection~~ injktion
Project description
Injkt (Dependency injection injktion)
Your simple python DI library built with good intentions.
Install
pip install injkt
Why?
Good question.
How?
import typing as ty
from injkt import Bind, Config, Injectable, Injktor, inject_args_deps
class IMailService(ty.Protocol):
def send_mail(self, subject: str, to: str) -> None:
...
class SmtpMailService(IMailService):
def send_mail(self, subject: str, to: str) -> None:
raise NotImplementedError()
injktor = Injktor(
Config(
{
Bind(IMailService, SmtpMailService),
}
)
)
@inject_args_deps
def business_logic(mail_service=Injectable(IMailService)):
mail_service.send_mail("Hello", "world")
business_logic()
Class Based
from injktor import inject_attr_deps
@inject_attr_deps
class BusinessLogic:
mail_service = Injectable(IMailService)
def do_business_logic(self) -> None:
self.mail_service.send_mail("Hello", "world")
BusinessLogic().do_business_logic()
Class based lazy injection
from injktor import InjktLazy
class BusinessLogic(InjktLazy):
mail_service = Injectable(IMailService)
def do_business_logic(self) -> None:
self.mail_service.send_mail("Hello", "world")
BusinessLogic().do_business_logic()
Re-init dependencies
injktor = Injktor(
Config(
{
Bind(IMailService, SmtpMailService, always_reinit=True),
}
)
)
Enabling always_reinit will re-initialize the dependency on each call.
NOTE: It won't be re-initialized in the same class if you aren't using InjktLazy
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
injkt-0.1.0.tar.gz
(3.4 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
injkt-0.1.0-py3-none-any.whl
(5.6 kB
view details)
File details
Details for the file injkt-0.1.0.tar.gz.
File metadata
- Download URL: injkt-0.1.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.6 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c01201237fbbc8c5334043d60fb08bb23a9486ab161a91d2d41c5dd70d9a6520
|
|
| MD5 |
d00fc5664daec1449b809cd90240fd7d
|
|
| BLAKE2b-256 |
889670c0f0e8316885485a00c5c9f4161a10f7511e357302d5d06e8f4c88d960
|
File details
Details for the file injkt-0.1.0-py3-none-any.whl.
File metadata
- Download URL: injkt-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.6 Darwin/23.1.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d46052c32a1270b08b3ee371ccd3ced5f32596ccca2fde093371a4c92212c0b1
|
|
| MD5 |
f35677e482b9fde29040da901c9f6d26
|
|
| BLAKE2b-256 |
28793387a808771e5541e907841661f6f6dd41412115a262ce02f16657eb3903
|