Esempio n. 1
0
    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
Esempio n. 2
0
    def modify_services(self, services: List[Service],
                        aliases: List[ServiceAlias], parameters: Box):
        if is_running_in_console():
            aliases.append(
                ServiceAlias("databricksbundle.logger",
                             "consolebundle.logger"))
        else:
            service = Service("databricksbundle.logger",
                              DType("logging", "Logger"))
            service.set_factory(
                ServiceArgument(NotebookLoggerFactory.__module__), "create")

            services.append(service)

        return services, aliases
Esempio n. 3
0
    def test_factory(self):
        result = self.__service_parser.parse(
            "injecta.api.ApiClient",
            {
                "factory":
                ["@injecta.api.ApiClientFactory.ApiClientFactory", "create"],
                "arguments": [
                    "Jirka",
                ],
            },
        )
        expected = Service(
            "injecta.api.ApiClient",
            DType("injecta.api", "ApiClient"),
            [
                PrimitiveArgument("Jirka"),
            ],
        )
        expected.set_factory(
            ServiceArgument("injecta.api.ApiClientFactory.ApiClientFactory"),
            "create")

        self.assertEqual(expected, result)