diff --git a/src/dependency_injector/schema.py b/src/dependency_injector/schema.py index b1971f08..8608a816 100644 --- a/src/dependency_injector/schema.py +++ b/src/dependency_injector/schema.py @@ -150,18 +150,21 @@ class SchemaProcessorV1: return None for segment in segments[1:]: - if segment == 'as_int()': - provider = provider.as_int() - elif segment == 'as_float()': - provider = provider.as_float() - elif segment.startswith('is_'): # TODO - provider = provider.as_(str) - ... - else: - try: - provider = getattr(provider, segment) - except AttributeError: - return None + parentheses = '' + if '(' in segment and ')' in segment: + parentheses = segment[segment.find('('):segment.rfind(')')+1] + segment = segment.replace(parentheses, '') + + try: + provider = getattr(provider, segment) + except AttributeError: + # TODO + return None + + if parentheses: + # TODO + provider = provider() + return provider diff --git a/tests/unit/samples/schemasample/container-boto3-session.yml b/tests/unit/samples/schemasample/container-boto3-session.yml new file mode 100644 index 00000000..7f530a4e --- /dev/null +++ b/tests/unit/samples/schemasample/container-boto3-session.yml @@ -0,0 +1,26 @@ +version: "1" + +container: + + config: + provider: Configuration + + session: + provider: Singleton + provides: boto3.session.Session + kwargs: + aws_access_key_id: container.config.aws_access_key_id + aws_secret_access_key: container.config.aws_secret_access_key + aws_session_token: container.config.aws_session_token + + s3_client: + provider: Factory + provides: container.session.provided.client.call() + kwargs: + service_name: s3 + + sqs_client: + provider: Factory + provides: container.session.provided.client.call() + kwargs: + service_name: sqs diff --git a/tests/unit/schema/test_integration_py36.py b/tests/unit/schema/test_integration_py36.py index 3360e742..38a48a04 100644 --- a/tests/unit/schema/test_integration_py36.py +++ b/tests/unit/schema/test_integration_py36.py @@ -273,3 +273,13 @@ class TestSchemaMultipleContainersWithInlineProviders(unittest.TestCase): self.assertIs(photo_service1.s3, photo_service2.s3) self.assertIs(photo_service1.s3, container.gateways.s3_client()) self.assertIs(photo_service2.s3, container.gateways.s3_client()) + + +class TestSchemaBoto3Session(unittest.TestCase): + + def test(self): + container = containers.DynamicContainer() + container.from_yaml_schema(f'{_SAMPLES_DIR}/schemasample/container-boto3-session.yml') + + self.assertEqual(container.s3_client().__class__.__name__, 'S3') + self.assertEqual(container.sqs_client().__class__.__name__, 'SQS')