harp.services

exception CannotResolveParameterException[source]

Bases: DIException

Exception risen when it is not possible to resolve a parameter, necessary to instantiate a type.

__init__(param_name, desired_type)[source]
exception CannotResolveTypeException[source]

Bases: DIException

Exception risen when it is not possible to resolve a Type.

__init__(desired_type)[source]
exception CircularDependencyException[source]

Bases: DIException

Exception risen when a circular dependency between a type and one of its parameters is detected.

__init__(expected_type, desired_type)[source]
exception DIException[source]

Bases: Exception

Base exception class for DI exceptions.

exception FactoryMissingContextException[source]

Bases: DIException

__init__(function)[source]
Return type:

None

exception MissingTypeException[source]

Bases: DIException

Exception risen when a type must be specified to use a factory

__init__()[source]
exception OverridingServiceException[source]

Bases: DIException

Exception risen when registering a service would override an existing one.

__init__(key, value)[source]
exception UnsupportedUnionTypeException[source]

Bases: DIException

Exception risen when a parameter type is defined as Optional or Union of several types.

__init__(param_name, desired_type)[source]
class Container[source]

Bases: Container

Override’s rodi container with our way to load services. This is a working implementation, although it would need polishing. Maybe the container should be reworked entirely to avoid the rodi duplications entirely, here the api methods using the builtin rodi providers/resolvers are still available, and that’s maybe not what we want, for the long term.

load(filename, *, bind_settings)[source]

Loads a declarative service collection from a yaml file, and bind settings for config resolution.

Parameters:
  • filename – str

  • bind_settings – dict-like

strict
class LazyServiceReference[source]

Bases: BaseReference

Reference to a service, that will be resolved the latest possible, when the instance will actually be needed.

Create a new model by parsing and validating input data from keyword arguments.

Raises pydantic_core.ValidationError if the input data cannot be validated.

classmethod build_from_yaml(loader, node)[source]

Secondary constructor implementing the pyyaml constructor interface.

Return type:

Self

resolve(resolver, context)[source]

Resolve reference value in using the given resolver (callable) and resolution context.

model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[Dict[str, FieldInfo]] = {'target': FieldInfo(annotation=Union[str, list[str]], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo] objects.

This replaces Model.__fields__ from Pydantic V1.

target: str | list[str]

Reference target, a.k.a. the service symbolic name. Can be either a string, or a list of strings. The later will resolve as the first available service in the list.

class Services[source]

Bases: object

Provides methods to activate instances of classes, by cached activator functions.

__init__(services_map=None)[source]
exec(method, scoped=None)[source]
Parameters:
Return type:

Any

get(desired_type, scope=None, *, default=Ellipsis)[source]

Gets a service of the desired type, returning an activated instance.

Parameters:
  • desired_type (Type[T] | str) – desired service type.

  • context – optional context, used to handle scoped services.

  • scope (ActivationScope | None)

  • default (Any | None)

Returns:

an instance of the desired type

Return type:

T

get_executor(method)[source]
Parameters:

method (Callable)

Return type:

Callable

set(new_type, value)[source]

Sets a new service of desired type, as singleton. This method exists to increase interoperability of Services class (with dict).

Parameters:
Returns:

Submodules