This repository was archived by the owner on Aug 10, 2024. It is now read-only.
V1.2.0
Bug fix
- Fix injection error when using the
Klass | Nonenotation instead ofOptional[Klass]in Python 3.10.
Features
frozenkeyword argument toworld.test.clone()which allows one to control whether the cloned world is already frozen or not.- Both
inject.getandworld.getnow strictly follow the same API. interface()andimplements()which provide a cleaner way to separate implementations from the public interface. Qualifiers are also supported out of the box. They can be added withqualified_bykeyword and requested with eitherqualified_byorqualified_by_one_of.
from antidote import implements, inject, interface, world, QualifiedBy
V1 = object()
V2 = object()
@interface
class Service:
pass
@implements(Service).when(qualified_by=V1)
class ServiceImpl(Service):
pass
@implements(Service).when(QualifiedBy(V2))
class ServiceImplV2(Service):
pass
world.get[Service].single(qualified_by=V1)
world.get[Service].all()
@inject
def f(service: Service = inject.me(QualifiedBy(V2))) -> Service:
return service
@inject
def f(services: list[Service] = inject.me(qualified_by=[V1, V2])) -> list[Service]:
return servicesExperimental
PredicateAPI is experimental allows you to define your custom logic for selecting the right implementation for a given interface. Qualifiers are implemented with theQualifiedBypredicate which is part of the public API.