Skip to content

Commit

Permalink
Refactoring (#8)
Browse files Browse the repository at this point in the history
* Rename Depends to Provide

* Use weakref

* Remove ResolvedDependency

* Rearrange code and add docstrings

* Refactor resource decorator

* More refactoring

* More refactoring

* Duplicated code; I don't know how to rewrite this in a nice way

* Add init_resources

* trying to refactor more [meh]

* Add lock

* Update README.md
  • Loading branch information
yakimka authored Apr 23, 2024
1 parent 3a7c07a commit 3f2746c
Show file tree
Hide file tree
Showing 10 changed files with 315 additions and 187 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@

Simple Dependency Injection for Python


## Features

- Add yours!

Experimental dependency injection library for Python. Use it at your own risk.

## Installation

```bash
pip install nanodi
```


## Example

Showcase how your project can be used:

```python
from nanodi.example import some_function
from nanodi import inject, Provide


def get_redis() -> str:
yield "redis"
print("closing redis")


@inject
def get_storage_service(redis: str = Provide(get_redis)) -> str:
return f"storage_service({redis})"


print(some_function(3, 4))
# => 7
assert get_storage_service() == "storage_service(redis)"
```

## License
Expand Down
4 changes: 2 additions & 2 deletions nanodi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from nanodi.nanodi import Depends, inject, resource, shutdown_resources
from nanodi.nanodi import Provide, init_resources, inject, resource, shutdown_resources

__all__ = ["Depends", "inject", "shutdown_resources", "resource"]
__all__ = ["Provide", "inject", "init_resources", "shutdown_resources", "resource"]
Loading

0 comments on commit 3f2746c

Please sign in to comment.