Skip to content

Commit e6a2e5e

Browse files
committed
Update documentation.
1 parent 16730e4 commit e6a2e5e

File tree

6 files changed

+43
-100
lines changed

6 files changed

+43
-100
lines changed

docs/concepts.rst

-67
This file was deleted.

docs/examples.rst

+24-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
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.
6+
57
.. code-block:: python
68
79
# Get the default dependency container
@@ -17,6 +19,8 @@ Creating dependency containers
1719
Registering dependencies with scopes
1820
####################################
1921

22+
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.
23+
2024
.. code-block:: python
2125
2226
# Register a transient dependency
@@ -43,6 +47,8 @@ Registering dependencies with scopes
4347
Registering with constructor arguments
4448
######################################
4549

50+
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.
51+
4652
.. code-block:: python
4753
4854
# Register with constructor arguments
@@ -60,8 +66,10 @@ Registering with constructor arguments
6066
Resolving with factory functions
6167
################################
6268

69+
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.
70+
6371
.. note::
64-
Any `callable <https://docs.python.org/3/glossary.html#term-callable>`_ can be used as factory function.
72+
Any `callable <https://docs.python.org/3/glossary.html#term-callable>`_ can be used as factory.
6573

6674
.. code-block:: python
6775
@@ -123,6 +131,8 @@ Resolving with factory functions
123131
Registering and using instances
124132
###############################
125133

134+
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.
135+
126136
.. code-block:: python
127137
128138
# Create instance
@@ -146,6 +156,8 @@ Registering and using instances
146156
Registering and resolving with tags
147157
###################################
148158

159+
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.
160+
149161
.. code-block:: python
150162
151163
# Register with tags
@@ -168,7 +180,7 @@ Registering and resolving with tags
168180
}
169181
)
170182
171-
# Resolve all dependencies with a specific tag
183+
# Resolve all dependencies with the 'Startable' tag
172184
resolved_dependencies = dependency_container.resolve_all(
173185
tags={
174186
Startable
@@ -184,6 +196,8 @@ Registering and resolving with tags
184196
Using constructor injection
185197
###########################
186198

199+
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.
200+
187201
.. code-block:: python
188202
189203
class OrderRepository:
@@ -213,6 +227,14 @@ Using constructor injection
213227
Using method injection
214228
######################
215229

230+
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.
231+
232+
.. note::
233+
You can pass the arguments ``container_name`` and ``scope_name`` to ``@inject``.
234+
235+
.. note::
236+
The ``@inject`` has to be applied to the function after the ``@classmethod`` or ``@staticmethod``.
237+
216238
.. code-block:: python
217239
218240
class OrderController:
@@ -236,6 +258,3 @@ Using method injection
236258
OrderController.place_order(
237259
order=Order.create()
238260
)
239-
240-
.. note::
241-
You can pass ``container_name`` and ``scope_name`` arguments to the ``@inject`` decorator to specify container and/or scope. If none of the arguments are passed, the `default container` and the `default scope` will be used.

docs/index.rst

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
.. warning::
2+
3+
This library is currently in the alpha stage of development. Expect changes and improvements as we work towards a stable release.
4+
15
py-dependency-injection
26
=======================
37

@@ -15,28 +19,12 @@ Key Advantages
1519

1620
- **Suitable for Learning:** Ideal for beginners exploring the concept of dependency injection.
1721
- **Base Implementation for Frameworks:** Can be used as a foundational base for frameworks requiring a more specialized interface for dependency injection.
18-
- **Standalone Solution:** Can be used on its own as a dependency injection solution in any software project.
19-
20-
Features
21-
--------
22-
23-
- Dependency Containers
24-
- Dependency Scopes
25-
- Constructor Injection
26-
- Method Injection
27-
- Factory Registration
28-
- Instance Registration
29-
- Tag-Based Resolution
30-
31-
Documentation
32-
-------------
33-
34-
For a detailed guide on how to use `py-dependency-injection`, please refer to the examples.
22+
- **Standalone Solution:** Can also be used on its own, as a fully-featured dependency injection solution in any software project.
3523

3624
.. userguide-docs:
3725
.. toctree::
3826
:maxdepth: 1
39-
:caption: User guide
27+
:caption: User Guide
4028

4129
userguide
4230

@@ -47,12 +35,12 @@ For a detailed guide on how to use `py-dependency-injection`, please refer to th
4735

4836
examples
4937

50-
.. versionhistory-docs:
38+
.. releases-docs:
5139
.. toctree::
5240
:maxdepth: 1
5341
:caption: Releases
5442

55-
versionhistory
43+
releases
5644

5745
.. apireference-docs:
5846
.. toctree::
@@ -61,4 +49,4 @@ For a detailed guide on how to use `py-dependency-injection`, please refer to th
6149

6250
py-modindex
6351

64-
You can find the source code for `py-dependency-injection` on `GitHub <https://github.com/runemalm/py-dependency-injection>`_.
52+
You can find the source code for `py-dependency-injection` in our `GitHub repository <https://github.com/runemalm/py-dependency-injection>`_.

docs/py-modindex.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
API reference
1+
API Reference
22
=============

docs/versionhistory.rst renamed to docs/releases.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
###############
2-
Version history
3-
###############
4-
51
.. warning::
62

73
This library is currently in the alpha stage of development. Expect changes and improvements as we work towards a stable release.
84

5+
###############
6+
Version History
7+
###############
8+
99
**1.0.0-alpha.7 (2024-03-24)**
1010

1111
- Documentation Update: Updated the documentation to provide clearer instructions and more comprehensive examples.

docs/userguide.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
############
1+
###############
2+
Getting Started
3+
###############
4+
25
Installation
3-
############
6+
---------------
47

58
Install using `pip <http://pypi.python.org/pypi/pip/>`_::
69

0 commit comments

Comments
 (0)