Skip to content

ioc_factory_model

Lightweight Inversion of Control (IoC) module

Attributes

IOC_CLASS_KEY module-attribute

IOC_CLASS_KEY = 'class'

Classes

IoCFactoryModel

Bases: SettingsBaseModel

Pydantic wrapper for dynamic class instantiation

Attributes

class_name class-attribute instance-attribute
class_name: str = Field(
    ...,
    alias=IOC_CLASS_KEY,
    description="Callable name that is used to create an instance of the class, usually this is the fully qualified class or function name",
)

Functions

ioc
ioc(overrides: Optional[Dict] = None) -> Any

Execute IoC initialization of the class_name.

Warning

When the configured class_name is a Class, then the class will be instantiated and returned. If the class_name is a function then kwarg parameters + overrides will be passed to it as if it were a class constructor. The function’s return value is returned in this case.

It is the responsibility of the caller to handle the return value properly.

Parameters:

  • overrides (Optional[Dict], default: None ) –

    A dictionary of attribute overrides for the new instance.

Returns:

  • Any ( Any ) –

    The newly created class instance or function result.