import importlib


def _lazy(module, classname):
    """Return a builder that lazily imports module.classname on first call."""
    def build(*args, **kwargs):
        return getattr(importlib.import_module(module), classname)(*args, **kwargs)
    return build


class ComponentFactory:
    _registry = {}

    @classmethod
    def create(cls, name, *args, **kwargs):
        for key, builder in cls._registry.items():
            if key in name:
                return builder(*args, **kwargs)
        raise ValueError(f"{cls.__name__}: unknown name {name!r}")
