Open generics¶
Open generics let you register a single factory for a generic type, and then resolve it for any concrete type argument:
register
Repository[T]onceresolve
Repository[User],Repository[Order], …
diwire also validates TypeVar bounds/constraints at runtime.
Example¶
See the runnable script in Open generics.
How it works¶
You register an open generic key that contains one or more TypeVars (for example
AnyBox[T]).When you resolve a closed generic (for example
AnyBox[int]), diwire:matches the closed generic to the registered open generic
validates the concrete type arguments against TypeVar bounds/constraints
calls your factory and passes the concrete type argument(s) (for example
type[int]) as parameters