TypeRegistry¶
TypeRegistry is the runtime lookup table that maps graph type name strings to GraphType instances. Loaded modules register their GraphType objects here during application startup.
Registration¶
from knowledge_platform.domain.registry import TypeRegistry
from knowledge_platform.modules.outline.graph_type import OutlineGraphType
registry = TypeRegistry()
registry.register(OutlineGraphType())
# Look up later
gtype = registry.get("outline")
print(registry.registered_names()) # ["outline"]
Duplicate Registration¶
Attempting to register two types with the same type_name raises ValueError:
registry.register(OutlineGraphType()) # OK
registry.register(OutlineGraphType()) # ValueError: Graph type 'outline' is already registered.
Checking Registration¶
Usage in Application Bootstrap¶
In ui/app.py, ModuleLoader loads configured modules first, then registers their graph types before any graph is created:
from knowledge_platform.modules.loader import ModuleLoader
type_registry = TypeRegistry()
module_loader = ModuleLoader()
module_loader.register_into(type_registry, module_registry)
API Reference¶
knowledge_platform.domain.registry.TypeRegistry ¶
Singleton-style registry mapping graph type names to :class:GraphType instances.
Modules register their :class:GraphType implementations here during
startup. The :class:~knowledge_platform.services.graph_service.GraphService
looks up types at creation time to validate new graphs.
Example::
registry = TypeRegistry()
registry.register(OutlineGraphType())
gtype = registry.get("outline")
Source code in src/knowledge_platform/domain/registry.py
Functions¶
get ¶
Return the :class:GraphType for type_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_name
|
str
|
Registered type name. |
required |
Returns:
| Type | Description |
|---|---|
GraphType
|
The corresponding :class: |
Raises:
| Type | Description |
|---|---|
KeyError
|
If type_name is not registered. |
Source code in src/knowledge_platform/domain/registry.py
is_registered ¶
Return True if type_name is currently registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_name
|
str
|
Type name to query. |
required |
register ¶
Register a :class:GraphType instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_type
|
GraphType
|
The type to register. Its :attr: |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If type_name is already registered. |