Skip to content

Commit 3afdfaf

Browse files
committed
docs: configuration recipe
1 parent d194d12 commit 3afdfaf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,23 @@ user_creator = UserCreator(repository)
193193
user_creator.create(fake_user)
194194
```
195195

196+
### Configuration
197+
198+
There are multiple ways to configure your classes. A simple approach is to use environment variables on your factory
199+
annotated methods.
200+
201+
```python
202+
import os
203+
from quickd import factory
204+
205+
206+
@factory
207+
def choose_database() -> Database:
208+
username = os.environ.get("POSTGRES_USER")
209+
password = os.environ.get("POSTGRES_PASS")
210+
return PostgreSQL(username, password)
211+
```
212+
196213
## 🧠 Motivation
197214

198215
Dependency injection provides a great way to decouple your classes in order to improve testability and maintainability.

0 commit comments

Comments
 (0)