def parse(self, service_name: str, raw_service: dict = None): if raw_service is None: return Service(service_name, self.__type_resolver.resolve(service_name)) arguments = self.__parse_arguments(raw_service) tags = raw_service["tags"] if "tags" in raw_service else [] class_ = self.__type_resolver.resolve( raw_service["class"] if "class" in raw_service else service_name) service = Service(service_name, class_, arguments, tags) if "autowire" in raw_service: service.set_autowire(raw_service["autowire"] is True) if "factory" in raw_service: if raw_service["factory"][0][0:1] != "@": raise Exception( "Factory service name must be prefixed with @ (service {})" .format(service_name)) service.set_factory(ServiceArgument(raw_service["factory"][0][1:]), raw_service["factory"][1]) return service
def test_basic(self): result = self.__service_parser.parse( "injecta.api.ApiClient_test", { "class": "injecta.api.ApiClient.ApiClient", "autowire": True, "arguments": ["Jirka", 15, False, "@injecta.api.Connector"] }, ) expected = Service( "injecta.api.ApiClient_test", DType("injecta.api.ApiClient", "ApiClient"), [ PrimitiveArgument("Jirka"), PrimitiveArgument(15), PrimitiveArgument(False), ServiceArgument("injecta.api.Connector"), ], ) expected.set_autowire(True) self.assertEqual(expected, result)