Skip to content

Value Provider

Provide given an object "as is".

Simple Usage
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from types import SimpleNamespace
import uzi

class Config(SimpleNamespace):
    debug: bool = False
    database: str

config = Config(debug=True, database=':memory:')

container = uzi.Container()

# a) using the helper method
container.value(Config, config) 
# or 
# b) manually creating and attaching the provider
container[Config] = uzi.providers.Value(config)


if __name__ == '__main__':
    injector = uzi.Injector(uzi.DepGraph(container))

    assert config == injector.make(Config)
    assert config is injector.make(Config)
Back to top