Skip to content

Commit

Permalink
Update wiring docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Sep 30, 2021
1 parent 9f7ec7e commit 9f51ea2
Showing 1 changed file with 47 additions and 8 deletions.
55 changes: 47 additions & 8 deletions docs/wiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,65 @@ You could also use string identifiers to avoid a dependency on a container:
Wiring with modules and packages
--------------------------------

To wire a container with a module you need to call ``container.wire(modules=[...])`` method. Argument
``modules`` is an iterable of the module objects.
To wire a container with the modules you need to call ``container.wire()`` method:

.. code-block:: python
from yourapp import module1, module2
container.wire(
modules=[
"yourapp.module1",
"yourapp.module2",
],
)
Method ``container.wire()`` can resolve relative imports:

container = Container()
container.wire(modules=[module1, module2])
.. code-block:: python
You can wire container with a package. Container walks recursively over package modules.
# In module "yourapp.foo":
container.wire(
modules=[
".module1", # Resolved to: "yourapp.module1"
".module2", # Resolved to: "yourapp.module2"
],
)
You can also manually specify a base package for resolving relative imports with
the ``from_package`` argument:

.. code-block:: python
from yourapp import package1, package2
# In module "yourapp.main":
container.wire(
modules=[
".module1", # Resolved to: "anotherapp.module1"
".module2", # Resolved to: "anotherapp.module2"
],
from_package="anotherapp",
)
Argument ``modules`` can also take already imported modules:

.. code-block:: python
from yourapp import module1, module2
container = Container()
container.wire(packages=[package1, package2])
container.wire(modules=[module1, module2])
You can wire container with a package. Container walks recursively over the package modules:

.. code-block:: python
container.wire(
packages=[
"yourapp.package1",
"yourapp.package2",
],
)
Arguments ``modules`` and ``packages`` can be used together.

Expand Down

0 comments on commit 9f51ea2

Please sign in to comment.