Skip to main content

Object Instantiation

If the component is a literal, then it is returned as is:

3

will result in

3

If the component definition is a mapping with a "type" field, the factory will lookup the CLASS_TYPES_REGISTRY and replace the "type" field by "class_name" -> CLASS_TYPES_REGISTRY[type] and instantiate the object from the resulting mapping

If the component definition is a mapping with neither a "class_name" nor a "type" field, the factory will do a best-effort attempt at inferring the component type by looking up the parent object's constructor type hints. If the type hint is an interface present in DEFAULT_IMPLEMENTATIONS_REGISTRY, then the factory will create an object of its default implementation.

If the component definition is a list, then the factory will iterate over the elements of the list, instantiate its subcomponents, and return a list of instantiated objects.

If the component has subcomponents, the factory will create the subcomponents before instantiating the top level object

{
"type": TopLevel
"param":
{
"type": "ParamType"
"k": "v"
}
}

will result in

TopLevel(param=ParamType(k="v"))

More details on object instantiation can be found here.