Skip to content

Commit f77572e

Browse files
committed
chore: replace dependency and args in docs
1 parent 5433c4f commit f77572e

File tree

3 files changed

+66
-59
lines changed

3 files changed

+66
-59
lines changed

docs/examples.rst

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Creating dependency containers
33
##############################
44

5-
In this example, we demonstrate how to create and retrieve dependency containers using the `DependencyContainer` class. This is useful when you want to manage dependencies in different contexts or areas of your application.
5+
In this example, we demonstrate how to create and retrieve dependency containers using the `DependencyContainer` class. This is useful when you want to manage services in different contexts or areas of your application.
66

77
.. code-block:: python
88
@@ -17,47 +17,47 @@ In this example, we demonstrate how to create and retrieve dependency containers
1717
)
1818
1919
20-
####################################
21-
Registering dependencies with scopes
22-
####################################
20+
################################
21+
Registering services with scopes
22+
################################
2323

24-
This example shows how to register dependencies with different scopes (transient, scoped, and singleton). This is important for controlling the lifecycle and reuse of your dependencies.
24+
This example shows how to register services with different scopes (transient, scoped, and singleton). This is important for controlling the lifecycle and reuse of your services.
2525

2626
.. code-block:: python
2727
28-
# Register a transient dependency
28+
# Register a transient service
2929
dependency_container.register_transient(
3030
Connection,
3131
PostgresConnection
3232
)
3333
34-
# Register a scoped dependency
34+
# Register a scoped service
3535
dependency_container.register_scoped(
3636
Connection,
3737
PostgresConnection,
3838
scope_name="http_request"
3939
)
4040
41-
# Register a singleton dependency
41+
# Register a singleton service
4242
dependency_container.register_singleton(
4343
Connection,
4444
PostgresConnection
4545
)
4646
4747
48-
######################################
49-
Registering with constructor arguments
50-
######################################
48+
###################################
49+
Registering with constructor kwargs
50+
###################################
5151

52-
Here, we illustrate how to register a dependency with constructor arguments. This allows you to provide specific values or configurations to your dependencies when they are instantiated.
52+
Here, we illustrate how to register a service with constructor keyword arguments. This allows you to provide specific values or configurations to your services when they are instantiated.
5353

5454
.. code-block:: python
5555
56-
# Register with constructor arguments
56+
# Register with constructor kwargs
5757
dependency_container.register_transient(
5858
Connection,
5959
PostgresConnection,
60-
constructor_args={
60+
constructor_kwargs={
6161
"host": "localhost",
6262
"port": 5432
6363
}
@@ -68,7 +68,7 @@ Here, we illustrate how to register a dependency with constructor arguments. Thi
6868
Resolving with factory functions
6969
################################
7070

71-
In this section, we demonstrate how to register and resolve dependencies using the factory pattern. This provides flexibility in how your dependencies are created and configured. You can use factory functions, factory classes and factory lambdas.
71+
In this section, we demonstrate how to register and resolve services using the factory pattern. This provides flexibility in how your services are created and configured. You can use factory functions, factory classes and factory lambdas.
7272

7373
.. note::
7474
Any `callable <https://docs.python.org/3/glossary.html#term-callable>`_ can be used as factory.
@@ -86,7 +86,7 @@ In this section, we demonstrate how to register and resolve dependencies using t
8686
dependency_container.register_factory(
8787
Connection,
8888
factory_function,
89-
factory_args={
89+
factory_kwargs={
9090
"host": "localhost",
9191
"port": 5432
9292
}
@@ -107,7 +107,7 @@ In this section, we demonstrate how to register and resolve dependencies using t
107107
dependency_container.register_factory(
108108
Connection,
109109
FactoryClass.create,
110-
factory_args={
110+
factory_kwargs={
111111
"host": "localhost",
112112
"port": 5432
113113
}
@@ -122,7 +122,7 @@ In this section, we demonstrate how to register and resolve dependencies using t
122122
host=host,
123123
port=port
124124
),
125-
factory_args={
125+
factory_kwargs={
126126
"host": "localhost",
127127
"port": 5432
128128
}
@@ -133,7 +133,7 @@ In this section, we demonstrate how to register and resolve dependencies using t
133133
Registering and using instances
134134
###############################
135135

136-
This example demonstrates how to register and use instances of your dependencies. This is useful when you want to provide a specific instance of a dependency for use throughout your application.
136+
This example demonstrates how to register and use instances of your services. This is useful when you want to provide a specific instance of a service for use throughout your application.
137137

138138
.. code-block:: python
139139
@@ -150,15 +150,15 @@ This example demonstrates how to register and use instances of your dependencies
150150
)
151151
152152
# Resolve instance
153-
resolved_instance = dependency_container.resolve(Connection)
154-
print(resolved_instance.host) # Output: localhost
153+
resolved = dependency_container.resolve(Connection)
154+
print(resolved.host) # Output: localhost
155155
156156
157157
###################################
158158
Registering and resolving with tags
159159
###################################
160160

161-
In this example, we show how to register and resolve dependencies using tags. This allows you to categorize and retrieve specific groups of dependencies based on their tags.
161+
In this example, we show how to register and resolve services using tags. This allows you to categorize and retrieve specific groups of services based on their tags.
162162

163163
.. code-block:: python
164164
@@ -172,7 +172,7 @@ In this example, we show how to register and resolve dependencies using tags. Th
172172
}
173173
)
174174
175-
# Register another dependency with tags
175+
# Register another service with tags
176176
dependency_container.register_scoped(
177177
BusConnection,
178178
KafkaBusConnection,
@@ -182,31 +182,31 @@ In this example, we show how to register and resolve dependencies using tags. Th
182182
}
183183
)
184184
185-
# Resolve all dependencies with the 'Startable' tag
186-
resolved_dependencies = dependency_container.resolve_all(
185+
# Resolve all services with the 'Startable' tag
186+
resolved = dependency_container.resolve_all(
187187
tags={
188188
Startable
189189
}
190190
)
191191
192-
# Use resolved dependencies
193-
for dependency in resolved_dependencies:
194-
dependency.start()
192+
# Use resolved services
193+
for service in resolved:
194+
service.start()
195195
196196
197197
###########################
198198
Using constructor injection
199199
###########################
200200

201-
This example illustrates how to use constructor injection to automatically inject dependencies into your classes. This is a common pattern for managing dependencies in object-oriented programming. This is probably how you'll want to resolve 99% of the dependencies in your software application.
201+
This example illustrates how to use constructor injection to automatically inject services into your classes. This is a common pattern for managing dependencies in object-oriented programming. This is probably how you'll want to resolve 99% of the services in your software application.
202202

203203
.. code-block:: python
204204
205205
class OrderRepository:
206206
def __init__(self, connection: Connection):
207207
self.connection = connection
208208
209-
# Register dependencies
209+
# Register services
210210
dependency_container.register_transient(
211211
OrderRepository
212212
)
@@ -216,20 +216,20 @@ This example illustrates how to use constructor injection to automatically injec
216216
PostgresConnection
217217
)
218218
219-
# Resolve with injected dependencies
219+
# Resolve with injected services
220220
repository = dependency_container.resolve(
221221
OrderRepository
222222
)
223223
224-
# Use injected dependency
224+
# Use injected service
225225
print(repository.connection.__class__.__name__) # Output: PostgresConnection
226226
227227
228-
######################################################
229-
Using constructor injection with tagged dependencies
230-
######################################################
228+
################################################
229+
Using constructor injection with tagged services
230+
################################################
231231

232-
This example demonstrates how to use constructor injection to automatically inject tagged dependencies into your classes. By leveraging tags, you can group and categorize dependencies, enabling automatic injection based on specific criteria.
232+
This example demonstrates how to use constructor injection to automatically inject tagged services into your classes. By leveraging tags, you can group and categorize services, enabling automatic injection based on specific criteria.
233233

234234
.. code-block:: python
235235
@@ -250,36 +250,36 @@ This example demonstrates how to use constructor injection to automatically inje
250250
self.primary_ports = primary_ports
251251
self.secondary_ports = secondary_ports
252252
253-
# Register dependencies with tags
253+
# Register services with tags
254254
dependency_container.register_transient(HttpAdapter, tags={PrimaryPort})
255255
dependency_container.register_transient(PostgresCarRepository, tags={SecondaryPort})
256256
257-
# Register the Application class to have its dependencies injected
257+
# Register the Application class to have its services injected
258258
dependency_container.register_transient(Application)
259259
260-
# Resolve the Application class, with tagged dependencies automatically injected
260+
# Resolve the Application class, with tagged services automatically injected
261261
application = dependency_container.resolve(Application)
262262
263-
# Use the injected dependencies
263+
# Use the injected services
264264
print(f"Primary ports: {len(application.primary_ports)}") # Output: Primary ports: 1
265265
print(f"Secondary ports: {len(application.secondary_ports)}") # Output: Secondary ports: 1
266266
print(f"Primary port instance: {type(application.primary_ports[0]).__name__}") # Output: HttpAdapter
267267
print(f"Secondary port instance: {type(application.secondary_ports[0]).__name__}") # Output: PostgresCarRepository
268268
269269
270-
In this example, the `Application` class expects lists of instances tagged with `PrimaryPort` and `SecondaryPort`. By tagging and registering these dependencies, the container automatically injects the correct instances into the `Application` class when it is resolved.
270+
In this example, the `Application` class expects lists of instances tagged with `PrimaryPort` and `SecondaryPort`. By tagging and registering these services, the container automatically injects the correct instances into the `Application` class when it is resolved.
271271

272-
Tags offer a powerful way to manage dependencies, ensuring that the right instances are injected based on your application's needs.
272+
Tags offer a powerful way to manage services, ensuring that the right instances are injected based on your application's needs.
273273

274274
.. note::
275-
You can also use the ``AnyTagged`` and ``AllTagged`` classes to inject dependencies based on more complex tagging logic. ``AnyTagged`` allows injection of any dependency matching one or more specified tags, while ``AllTagged`` requires the dependency to match all specified tags before injection. This provides additional flexibility in managing and resolving dependencies in your application.
275+
You can also use the ``AnyTagged`` and ``AllTagged`` classes to inject services based on more complex tagging logic. ``AnyTagged`` allows injection of any service matching one or more specified tags, while ``AllTagged`` requires the service to match all specified tags before injection. This provides additional flexibility in managing and resolving services in your application.
276276

277277

278278
######################
279279
Using method injection
280280
######################
281281

282-
This example demonstrates how to use method injection to inject dependencies into methods at runtime. This is useful for dynamically providing dependencies to class- or static methods, without affecting the entire class.
282+
This example demonstrates how to use method injection to inject services into methods at runtime. This is useful for dynamically providing services to class- or static methods, without affecting the entire class.
283283

284284
.. note::
285285
You can pass the arguments ``container_name`` and ``scope_name`` to ``@inject``.
@@ -296,7 +296,7 @@ This example demonstrates how to use method injection to inject dependencies int
296296
order.set_status("placed")
297297
repository.save(order)
298298
299-
# Register dependencies
299+
# Register services
300300
dependency_container.register_transient(
301301
OrderRepository
302302
)

docs/index.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ Key Advantages
2424
- **Test-friendly** – Designed for container isolation and overrides
2525
- **Minimalistic** – Easy to use, extend, and integrate
2626

27-
You can find the source code for `py-dependency-injection` in our `GitHub repository <https://github.com/runemalm/py-dependency-injection>`_.
28-
2927
.. userguide-docs:
3028
.. toctree::
3129
:maxdepth: 1

docs/userguide.rst

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ Introduction
1414

1515
This guide provides an overview of the key concepts and demonstrates how to start using the library effectively. For detailed examples, see the `Examples` section.
1616

17+
###########
18+
Terminology
19+
###########
20+
21+
In this guide:
22+
23+
- **Service** — an abstract type or protocol you depend on.
24+
- **Implementation** — a concrete class that fulfills the service.
25+
1726
############
1827
Installation
1928
############
@@ -46,10 +55,10 @@ Core Concepts and Features
4655

4756
`py-dependency-injection` offers:
4857

49-
- **Scoped Dependency Management**: Define lifetimes for your dependencies (e.g., transient, scoped, singleton).
50-
- **Flexible Registrations**: Use constructors, factories, or predefined instances for dependency registration.
51-
- **Tag-Based Organization**: Categorize and resolve dependencies using tags.
52-
- **Multiple Containers**: Isolate dependencies for different parts of your application.
58+
- **Scoped Service Management**: Define lifetimes for your services (transient, scoped, singleton).
59+
- **Flexible Registrations**: Use constructors, factories, or predefined instances for service registration.
60+
- **Tag-Based Organization**: Categorize and resolve services using tags.
61+
- **Multiple Containers**: Isolate services for different parts of your application.
5362

5463
Refer to the `Examples` section for detailed usage scenarios.
5564

@@ -58,13 +67,13 @@ Quick Start Overview
5867
####################
5968

6069
1. **Create a Dependency Container**:
61-
- The `DependencyContainer` is the core object for managing dependencies.
70+
- The `DependencyContainer` is the core object for registering and resolving services.
6271

63-
2. **Register Dependencies**:
64-
- Dependencies can be registered with different lifetimes: transient, scoped, or singleton.
72+
2. **Register Services**:
73+
- Services can be registered with different lifetimes: transient, scoped, or singleton.
6574

66-
3. **Resolve Dependencies**:
67-
- Use the container to resolve dependencies where needed.
75+
3. **Resolve Services**:
76+
- Use the container to resolve services where needed.
6877

6978
Basic workflow:
7079

@@ -81,7 +90,7 @@ Basic workflow:
8190
# Create a container
8291
container = DependencyContainer.get_instance()
8392
84-
# Register and resolve dependencies
93+
# Register and resolve services
8594
container.register_singleton(Connection, PostgresConnection)
8695
connection = container.resolve(Connection)
8796
print(type(connection).__name__) # Output: PostgresConnection
@@ -93,15 +102,15 @@ Best Practices
93102
- **Prefer Constructor Injection**: It promotes clear interfaces and testable components.
94103
- **Use the Right Lifetime**: Choose between transient, scoped, and singleton based on your component's role.
95104
- **Organize with Tags**: Use tag-based registration and resolution to group related services.
96-
- **Avoid Container Coupling**: Inject dependencies via constructors rather than accessing the container directly.
105+
- **Avoid Container Coupling**: Inject services via constructors rather than accessing the container directly.
97106
- **Use Multiple Containers When Needed**: For modular apps or test isolation, create dedicated containers.
98107

99108
#################
100109
Where to Go Next?
101110
#################
102111

103112
- **Examples**:
104-
Explore detailed examples of how to register, resolve, and manage dependencies effectively in the `Examples` section.
113+
Explore detailed examples of how to register, resolve, and manage services effectively in the `Examples` section.
105114

106115
- **Community and Support**:
107116
Join our community on GitHub to ask questions, report issues, or contribute to the project.

0 commit comments

Comments
 (0)