Motivation
Direct instantiation scatters construction logic, prevents governance, and couples application code to concrete implementations. When construction requires config, caching, thread-safety, and lifecycle management, doing it inline becomes unmanageable.
K9-AIF factories are static — they cannot be instantiated. They maintain a thread-safe registry and return cached instances. All major components are provisioned exclusively through factories.
Structure
- Static factory class with _registry: Dict[str, Type]
- bootstrap(config) — initialises the factory once per runtime
- register(name, cls) — adds a class to the registry
- get(name) — returns a cached instance, raises if unknown
- create(config) — config-driven selection, zero-config default
- Thread-safe via threading.Lock