.. meta::
   :description: diwire open generic examples: type-argument injection, overrides, specificity, scopes, and constraints.

Open generics
=============

What you'll learn
-----------------

- Register open-generic providers and resolve closed generic keys.
- Understand precedence and validation behavior.

Factory type argument
---------------------

Run locally
~~~~~~~~~~~

.. code-block:: bash

   uv run python examples/ex_08_open_generics/01_factory_type_argument.py

.. literalinclude:: ../../../examples/ex_08_open_generics/01_factory_type_argument.py
   :language: python
   :class: diwire-example py-run

Closed override
---------------

Run locally
~~~~~~~~~~~

.. code-block:: bash

   uv run python examples/ex_08_open_generics/02_closed_override.py

.. literalinclude:: ../../../examples/ex_08_open_generics/02_closed_override.py
   :language: python
   :class: diwire-example py-run

Specificity winner
------------------

Run locally
~~~~~~~~~~~

.. code-block:: bash

   uv run python examples/ex_08_open_generics/03_specificity_winner.py

.. literalinclude:: ../../../examples/ex_08_open_generics/03_specificity_winner.py
   :language: python
   :class: diwire-example py-run

Scoped open generics
--------------------

Run locally
~~~~~~~~~~~

.. code-block:: bash

   uv run python examples/ex_08_open_generics/04_scoped_open_generics.py

.. literalinclude:: ../../../examples/ex_08_open_generics/04_scoped_open_generics.py
   :language: python
   :class: diwire-example py-run

Constraint details
------------------

Run locally
~~~~~~~~~~~

.. code-block:: bash

   uv run python examples/ex_08_open_generics/05_open_generics_constraints_details.py

.. literalinclude:: ../../../examples/ex_08_open_generics/05_open_generics_constraints_details.py
   :language: python
   :class: diwire-example py-run
