class IMDBMovieDB(MovieDB, Service): __antidote__ = Service.Conf(singleton=False) def __init__(self, imdb_api: Annotated[ImdbAPI, From(imdb_factory)]): self._imdb_api = imdb_api def get_best_movies(self): pass
class DummyB(Service): __antidote__ = Service.Conf() def __init__(self, s: Provide[Service1]): pass def get(self, s: Provide[Service1]): pass
class DummyC(Service): __antidote__ = Service.Conf().with_wiring( methods=['__init__', 'get']) def __init__(self): pass def get(self, my_service: Provide[Service1]): pass
class IMDBMovieDB(MovieDB, Service): __antidote__ = Service.Conf(singleton=False) # New instance each time @inject({'imdb_api': ImdbAPI @ imdb_factory}) def __init__(self, imdb_api: ImdbAPI): self._imdb_api = imdb_api def get_best_movies(self): pass
class Service3(Service): __antidote__ = Service.Conf(singleton=False).with_wiring( dependencies=dict(i=Interface @ impl, service2=Service2 @ BuildS2)) def __init__(self, service1: Provide[Service1], service2: Service2, i: Interface): self.service1 = service1 self.service2 = service2 self.i = i def get(self, service1: Provide[Service1]): pass X = LazyMethodCall(get)
def test_conf_repr(): conf = Service.Conf() assert "scope" in repr(conf)
def test_invalid_copy(): conf = Service.Conf() with pytest.raises(TypeError, match=".*both.*"): conf.copy(singleton=False, scope=None)
def test_conf_copy(kwargs): conf = Service.Conf(singleton=True).copy(**kwargs) for k, v in kwargs.items(): assert getattr(conf, k) == v
def test_invalid_conf_args(kwargs, expectation): with expectation: Service.Conf(**kwargs)
class A(Service): __antidote__ = Service.Conf(parameters=parameters)
class Scoped(Service): __antidote__ = Service.Conf(scope=dummy_scope)
class Service1(Service): __antidote__ = Service.Conf(parameters=['test'])
class MyService(Service): __antidote__ = Service.Conf(scope=dummy_scope)
class DummyA(Service): __antidote__ = Service.Conf(wiring=None) @inject def __init__(self, service: Provide[Service1]): pass
class Singleton(Service): __antidote__ = Service.Conf(singleton=True)
class NoScope(Service): __antidote__ = Service.Conf(singleton=False)
class A(Service): __antidote__ = Service.Conf(parameters=['x']) def __init__(self, x: str = 'default'): self.x = x
class A(Service): __antidote__ = Service.Conf(parameters=['x']) def __init__(self, **kwargs): self.kwargs = kwargs
class B(Service): __antidote__ = Service.Conf(parameters=['x']) def __init__(self, x: Provide[A]): self.x = x