Registry
provide.foundation.hub.registry
¶
TODO: Add module docstring.
Classes¶
Registry
¶
Multi-dimensional registry for storing and retrieving objects.
Supports hierarchical organization by dimension (component, command, etc.) and name within each dimension. This is a generic registry that can be used for any type of object storage and retrieval.
Thread-safe: All operations are protected by an RLock for safe concurrent access.
Note: Uses threading.RLock (not asyncio.Lock) for thread safety. For async-only applications with high-frequency registry access in request hot-paths (>10k req/sec with runtime registration), consider using an async-native registry implementation with asyncio.Lock. For typical use cases (initialization-time registration, CLI apps, read-heavy workloads), the threading lock has negligible impact.
See: docs/architecture/design-decisions.md#threading-model
Initialize an empty registry.
Source code in provide/foundation/hub/registry.py
Functions¶
__contains__
¶
Check if an item exists in the registry.
Source code in provide/foundation/hub/registry.py
__iter__
¶
Iterate over all registry entries.
Source code in provide/foundation/hub/registry.py
__len__
¶
clear
¶
Clear the registry or a specific dimension.
Source code in provide/foundation/hub/registry.py
dispose_all
¶
get
¶
Get an item from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name or alias of the item |
required |
dimension
|
str | None
|
Optional dimension to search in |
None
|
Returns:
| Type | Description |
|---|---|
Any | None
|
The registered value or None if not found |
Source code in provide/foundation/hub/registry.py
get_by_type
¶
Get a registered instance by its type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_hint
|
type[Any]
|
Type to look up |
required |
Returns:
| Type | Description |
|---|---|
Any | None
|
Registered instance or None if not found |
Example
db = registry.get_by_type(DatabaseClient)
Source code in provide/foundation/hub/registry.py
get_entry
¶
Get the full registry entry.
Source code in provide/foundation/hub/registry.py
list_all
¶
list_dimension
¶
list_types
¶
register
¶
register(
name: str,
value: Any,
dimension: str = "default",
metadata: dict[str, Any] | None = None,
aliases: list[str] | None = None,
replace: bool = False,
) -> RegistryEntry
Register an item in the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name within the dimension |
required |
value
|
Any
|
The item to register |
required |
dimension
|
str
|
Registry dimension for categorization |
'default'
|
metadata
|
dict[str, Any] | None
|
Optional metadata about the item |
None
|
aliases
|
list[str] | None
|
Optional list of aliases for this item |
None
|
replace
|
bool
|
Whether to replace existing entries |
False
|
Returns:
| Type | Description |
|---|---|
RegistryEntry
|
The created registry entry |
Raises:
| Type | Description |
|---|---|
ValueError
|
If name already exists and replace=False |
Source code in provide/foundation/hub/registry.py
register_type
¶
Register an instance by its type for dependency injection.
This enables type-based lookup which is essential for DI patterns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_hint
|
type[Any]
|
Type to register under |
required |
instance
|
Any
|
Instance to register |
required |
name
|
str | None
|
Optional name for standard registry (defaults to type name) |
None
|
Example
registry.register_type(DatabaseClient, db_instance) db = registry.get_by_type(DatabaseClient)
Source code in provide/foundation/hub/registry.py
remove
¶
Remove an item from the registry.
Returns:
| Type | Description |
|---|---|
bool
|
True if item was removed, False if not found |