Alias Provider¶
Used to "alias" another existing dependency.
Simple Usage | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
In the above snippet, dependents of both _Tb
and _Ta
will be provided with obj
.
Use Case¶
import typing as t
from uzi import Container, providers
_Ta = t.TypeVar('_Ta')
_Tb = t.TypeVar('_Tb')
class Cache:
...
class DbCache(Cache):
...
class MemoryCache(Cache):
...
class RedisCache(Cache):
...
container = Container()
container.singleton(DbCache)
container.singleton(RedisCache)
container.singleton(MemoryCache)
container.alias(Cache, RedisCache)