Skip to main content

Dependency-free dependency injection container for appfx packages.

Project description

appfx-di

CI Publish PyPI Python versions License: MIT

appfx-di provides a small, dependency-free dependency injection container for Python applications and reusable appfx components.

Package identity

Purpose Name
Distribution appfx-di
Import namespace appfx.di
Repository https://github.com/Dongbumlee/appfx-di
Supported Python 3.12, 3.13

Installation

python -m pip install appfx-di

For local development:

python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

Quickstart

from appfx.di import Container, Lifetime


class Greeter:
    def greet(self) -> str:
        return "hello"


class LoudGreeter(Greeter):
    def greet(self) -> str:
        return "HELLO"


container = Container()
container.add_type(Greeter, lifetime=Lifetime.SINGLETON)
container.add_type(Greeter, LoudGreeter, name="loud")

default_greeter = container.get_service(Greeter)
loud_greeter = container.get_service(Greeter, name="loud")

assert default_greeter.greet() == "hello"
assert loud_greeter.greet() == "HELLO"

Scoped services

from appfx.di import Container, Lifetime

container = Container()
container.add_type(RequestState, lifetime=Lifetime.SCOPED)

async with container.create_scope() as scope:
    first = scope.get_service(RequestState)
    second = scope.get_service(RequestState)
    assert first is second

Scoped services must be resolved within an active scope. Scope disposal cleans up created scoped services in reverse creation order. shutdown_async() cleans up created singleton instances and clears singleton caches.

Validation

python -m ruff check .
python -m ruff format --check .
python -m pytest --cov
python -m mypy
python -m build
python -m twine check dist\*

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

appfx_di-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

appfx_di-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file appfx_di-0.1.0.tar.gz.

File metadata

  • Download URL: appfx_di-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for appfx_di-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bb34625b679d8e2da656d0664f2292c79d3608c118e036e7e36be9f885c749b5
MD5 2a6da013e1482eabe6f0bb67a71afdba
BLAKE2b-256 de7583f50eab4065bb52bcfb1f35d26df300298aa57aa52f1fe146e06f42cfb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for appfx_di-0.1.0.tar.gz:

Publisher: publish.yml on Dongbumlee/appfx-di

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file appfx_di-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: appfx_di-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for appfx_di-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a63b173a58add39d66e22ffa3c2db6977d4e6ebcd37211b746c77460b2ddbf30
MD5 956c68e3019c1b1f561c0473881777a3
BLAKE2b-256 5e95da81dad29b25eb906c6bc3bbdb7913f0bdbc05ec023bad8a4bebb39f8ece

See more details on using hashes here.

Provenance

The following attestation bundles were made for appfx_di-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Dongbumlee/appfx-di

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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