Skip to content

Commit

Permalink
add docs for some providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan committed Jul 26, 2024
1 parent c74f3a2 commit e8041c6
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/providers/callable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Callable

soon...
26 changes: 26 additions & 0 deletions docs/providers/coroutine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Coroutine

**Coroutine** provider creates a coroutine.

## Example

```python3
import asyncio

from injection import DeclarativeContainer, providers


async def coroutine(arg1, arg2):
await asyncio.sleep(0.1)
return arg1, arg2


class DIContainer(DeclarativeContainer):
provider = providers.Coroutine(coroutine, arg1=1, arg2=2)


if __name__ == "__main__":
arg1, arg2 = asyncio.run(DIContainer.provider())
assert (arg1, arg2) == (1, 2)

```
21 changes: 21 additions & 0 deletions docs/providers/object.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Object

**Object** provider returns an object “as is”.

## Example

```python3
from injection import DeclarativeContainer, providers


class Container(DeclarativeContainer):
provider1 = providers.Object("string")
provider2 = providers.Object(13425)


if __name__ == "__main__":
assert Container.provider1() == "string"
assert Container.provider2() == 13425


```
3 changes: 3 additions & 0 deletions docs/providers/partial_callable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Partial callable

soon...
3 changes: 3 additions & 0 deletions docs/providers/provided_instance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Provided instance

soon...
14 changes: 9 additions & 5 deletions docs/providers/singleton.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# Singleton

Singleton provider make caching for your object.
sfsfsfdf
**Singleton** provider creates and returns a new object on the first call
and caches it, and on subsequent calls it returns the cached object.

## Example

```python3
from dataclasses import dataclass

from injection import DeclarativeContainer, providers


@dataclass
class SingletonClass:
field: int


class DIContainer(DeclarativeContainer):
singleton_provider = providers.Singleton(SingletonClass, field=15)
provider = providers.Singleton(SingletonClass, field=15)


if __name__ == "__main__":
instance1 = DIContainer.singleton_provider()
instance2 = DIContainer.singleton_provider()
instance1 = DIContainer.provider()
instance2 = DIContainer.provider()

assert instance1 is instance2
assert instance1.field == 15

```
28 changes: 28 additions & 0 deletions docs/providers/transient.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Transient

**Transient** provider creates and returns a new object for each call.

## Example

```python3
from dataclasses import dataclass

from injection import DeclarativeContainer, providers


@dataclass
class SomeClass:
field: str


class DIContainer(DeclarativeContainer):
provider = providers.Transient(SomeClass, field="str_value")


if __name__ == "__main__":
instance1 = DIContainer.provider()
instance2 = DIContainer.provider()

assert instance1 is not instance2

```

0 comments on commit e8041c6

Please sign in to comment.