Closed gnkow closed 1 year ago
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.
Is there any similar class to providers.Selector from dependency_injector? I want have different implementations injected based on antidote constants values (env variables).