Metadata-Version: 2.4
Name: appfx-di
Version: 0.1.0
Summary: Dependency-free dependency injection container for appfx packages.
Author-email: DB Lee <dongbum@outlook.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Dongbumlee/appfx-di
Project-URL: Repository, https://github.com/Dongbumlee/appfx-di
Project-URL: Issues, https://github.com/Dongbumlee/appfx-di/issues
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: mypy>=1.9; extra == "dev"
Requires-Dist: pytest>=8.4; extra == "dev"
Requires-Dist: pytest-asyncio>=1.0; extra == "dev"
Requires-Dist: pytest-cov>=6.2; extra == "dev"
Requires-Dist: ruff>=0.5; extra == "dev"
Requires-Dist: twine>=6.1; extra == "dev"
Dynamic: license-file

# appfx-di

[![CI](https://github.com/Dongbumlee/appfx-di/actions/workflows/ci.yml/badge.svg)](https://github.com/Dongbumlee/appfx-di/actions/workflows/ci.yml)
[![Publish](https://github.com/Dongbumlee/appfx-di/actions/workflows/publish.yml/badge.svg)](https://github.com/Dongbumlee/appfx-di/actions/workflows/publish.yml)
[![PyPI](https://img.shields.io/pypi/v/appfx-di.svg)](https://pypi.org/project/appfx-di/)
[![Python versions](https://img.shields.io/pypi/pyversions/appfx-di.svg)](https://pypi.org/project/appfx-di/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Dongbumlee/appfx-di/blob/main/LICENSE)

`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

```powershell
python -m pip install appfx-di
```

For local development:

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

## Quickstart

```python
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

```python
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

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