How to define specific implementation in catalogue based on conditions?
Closed this issue · 1 comments
Is there any similar class to providers.Selector from dependency_injector? I want have different implementations injected based on antidote constants values (env variables).
from antidote import const, inject, interface, implements, world
CLOUD = const('AWS') # some configuration loader somewhere
@Inject
def on_cloud(expected: str, actual: str = inject[CLOUD]) -> bool:
return expected == actual
@interface
class CloudAPI:
pass
@implements(CloudAPI).when(on_cloud('GCP'))
class GCPapi(CloudAPI):
pass
@implements(CloudAPI).when(on_cloud('AWS'))
class AWSapi(CloudAPI):
pass
world[CloudAPI]
<AWSapi object ...>
Found it in docs. I would say this should be more visible on user guide as is a common user request. Ty, amazing package.