ThirVondukr / aioinject

Async-first python dependency injection library
https://thirvondukr.github.io/aioinject/
MIT License
30 stars 2 forks source link

Support batch override #3

Closed nrbnlulu closed 9 months ago

nrbnlulu commented 9 months ago
def test_override_batch() -> None:
    container = Container()
    container.register(Object(0))
    container.register(Object("barfoo"))

    with container.override_batch(
        Object(1),
        Object("foobar"),
    ), container.sync_context() as ctx:
        assert ctx.resolve(int) == 1
        assert ctx.resolve(str) == "foobar"

    with container.sync_context() as ctx:
        assert ctx.resolve(int) == 0
        assert ctx.resolve(str) == "barfoo"