Skip to content

Commit 61be767

Browse files
committed
Update README a bit.
1 parent 73c8ce1 commit 61be767

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ Here's a quick example to get you started:
3535
```python
3636
from dependency_injection.container import DependencyContainer
3737

38-
# Define dependency abstraction
38+
# Define an abstract Connection
3939
class Connection:
4040
pass
4141

42-
# Define dependency implementations
42+
# Define a specific implementation of the Connection
4343
class PostgresConnection(Connection):
4444
def connect(self):
4545
print("Connecting to PostgreSQL database...")
4646

47+
# Define a repository that depends on some type of Connection
4748
class UserRepository:
4849
def __init__(self, connection: Connection):
4950
self._connection = connection
@@ -52,17 +53,19 @@ class UserRepository:
5253
self._connection.connect()
5354
print("Fetching users from the database...")
5455

55-
# Get a dependency container
56+
# Get an instance of the (default) DependencyContainer
5657
container = DependencyContainer.get_instance()
5758

58-
# Register dependencies
59+
# Register the specific connection type as a singleton instance
5960
container.register_singleton(Connection, PostgresConnection)
61+
62+
# Register UserRepository as a transient (new instance every time)
6063
container.register_transient(UserRepository)
6164

62-
# Resolve dependencies
65+
# Resolve an instance of UserRepository, automatically injecting the required Connection
6366
user_repository = container.resolve(UserRepository)
6467

65-
# Use the dependencies
68+
# Use the resolved user_repository to perform an operation
6669
user_repository.find_all()
6770
```
6871

0 commit comments

Comments
 (0)