Union types
This page describes support for Union types in Rodi.
- Optional dependencies.
- Union types dependencies.
Optional dependencies¶
It is uncommon for types resolved with dependency injection to have optional dependencies, however this scenario is supported by Rodi.
Optional types keys.
Beware that if you specify a T dependency as optional, the key type used to resolve the dependency becomes the T | None and it is not just T.
A factory function can be used to define logic that determines how the dependency must be resolved:
Union dependencies¶
Union types are also supported:
Union types keys.
Beware that if you specify a union dependency such as T | U the key type
used to resolve the dependency is T | U. Trying to use T or U
singularly causes a CannotResolveTypeException
.
The next page provides an overview of errors raised by Rodi.
Last modified on: 2025-04-17 07:04:37