Adapter Registries
The dependency injection layer, where adapters are registered against the ports declared in hololinked.core.
Each registry below resolves an implementation by name, on first use.
| Registry | Resolves | Adapters live in |
|---|---|---|
Serializers |
serializers | hololinked.serializers |
SchemaValidators |
schema validators | hololinked.schema_validators |
StorageBackends |
storage backends | hololinked.storage |
MetadataFormats |
device description languages | hololinked.metadata |
The implementation is either already available in the package or can be supplied by the end user. All four classes above are singletons, so anything set on them applies process-wide.
hololinked.injection.AdapterRegistry
Bases: MappableSingleton
Metaclass that imports an adapter the first time it is asked for (i.e. a lazy import).
Adapter is a concrete implementation of a specific dependency, for example, JSONSchemaValidator is an adapter for
schema validation based on JSON schema, whereas pydantic is a different implementation. However, their interfaces
or external behaviour is similar, so they can be used interchangeably or for different technological reasons.
Each adapter lives in its own module, so resolving one never imports the dependencies of the others. This lets one install only the dependencies you need. For individual adapters types, for example schema validators or serializers, a registry class is defined that uses this metaclass to resolve adapters by name, as a lazy import at runtime.
This metaclass providers lazy import functionality.
Source code in repo/hololinked/hololinked/injection.py
Attributes
adapter_kind
class-attribute
What this registry holds ("serializers", "schema-validators", "ddl" etc.), used in error messages.
modules
class-attribute
Name of an implementation mapped to the class that provides it.
tables
class-attribute
Names of the registry's lookup dictionaries, snapshotted at class creation.
One can clear the cache using forget_adapters().
instantiate
class-attribute
Whether a resolved adapter class needs to be instantiated, or whether the class itself is what is used.
Functions
install
Caching the adapter so that subsequent access skips __getattr__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
the name to serve the adapter under |
required |
|
Any
|
the adapter, a class or an instance depending on the registry |
required |
Source code in repo/hololinked/hololinked/injection.py
forget_adapters
Drop every resolved adapter and restore the lookup tables, leaving the registry as it was on import.
Source code in repo/hololinked/hololinked/injection.py
hololinked.injection.Registry
Base for the registries below, so that a registry instance resolves adapters the way its class does.
All members are class attributes, and only the metaclass knows how to resolve an unresolved adapter