harp.services.models¶
- class BaseServiceDefinitionCollection[source]¶
Bases:
BaseModel
Base class for coherent sequences of services. The traverse() method can be used to get a flat iterator over all the service definitions in the collection and its children, ordered.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- 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]] = {'services': FieldInfo(annotation=Sequence[Annotated[Union[Annotated[ServiceDefinition, Tag], Annotated[BaseServiceDefinitionCollection, Tag], Annotated[ConditionalServiceDefinitionCollection, Tag]], Discriminator]], 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.
- services: Sequence[Annotated[Annotated[ServiceDefinition, Tag(tag=service)] | Annotated[BaseServiceDefinitionCollection, Tag(tag=collection)] | Annotated[ConditionalServiceDefinitionCollection, Tag(tag=conditional_collection)], Discriminator(discriminator=_discriminator, custom_error_type=None, custom_error_message=None, custom_error_context=None)]]¶
- class ConditionalServiceDefinitionCollection[source]¶
Bases:
BaseServiceDefinitionCollection
A collection of services that are only registered if a condition is met. This is useful for conditional service registration, for example based on a configuration value.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- condition: str | bool | LazySettingReference | Sequence[str | bool | LazySettingReference] | None¶
- 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]] = {'condition': FieldInfo(annotation=Union[str, bool, LazySettingReference, Sequence[Union[str, bool, LazySettingReference]], NoneType], required=False, default=None), 'services': FieldInfo(annotation=Sequence[Annotated[Union[Annotated[ServiceDefinition, Tag], Annotated[BaseServiceDefinitionCollection, Tag], Annotated[ConditionalServiceDefinitionCollection, Tag]], Discriminator]], 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.
- class ServiceDefinition[source]¶
Bases:
BaseModel
Describes a service that our container is able to register. Services within a collection can override each other, if explicitely stated. This is useful for conditional service change (for example, based on a configuration value).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- base: str | LazySettingReference | LazyServiceReference | Sequence[str | LazySettingReference | LazyServiceReference] | None¶
base type for service, aka the interface we are implementing, if different from type
- constructor: str | LazySettingReference | LazyServiceReference | Sequence[str | LazySettingReference | LazyServiceReference] | None¶
constructor name, if not default one
- model_computed_fields: ClassVar[Dict[str, ComputedFieldInfo]] = {}¶
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_fields: ClassVar[Dict[str, FieldInfo]] = {'arguments': FieldInfo(annotation=Union[Mapping[str, Any], Sequence[Union[Mapping[str, Any], LazySettingReference]], NoneType], required=False, default=None), 'base': FieldInfo(annotation=Union[str, LazySettingReference, LazyServiceReference, Sequence[Union[str, LazySettingReference, LazyServiceReference]], NoneType], required=False, default=None), 'constructor': FieldInfo(annotation=Union[str, LazySettingReference, LazyServiceReference, Sequence[Union[str, LazySettingReference, LazyServiceReference]], NoneType], required=False, default=None), 'defaults': FieldInfo(annotation=Union[Mapping[str, Any], Sequence[Union[Mapping[str, Any], LazySettingReference]], NoneType], required=False, default=None), 'description': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'lifestyle': FieldInfo(annotation=Union[Literal['singleton', 'transient', 'scoped'], NoneType], required=False, default=None), 'name': FieldInfo(annotation=str, required=True), 'override': FieldInfo(annotation=Union[str, NoneType], required=False, default=None), 'positionals': FieldInfo(annotation=Union[Tuple[Any, ...], NoneType], required=False, default=None), 'type': FieldInfo(annotation=Union[str, LazySettingReference, LazyServiceReference, Sequence[Union[str, LazySettingReference, LazyServiceReference]], NoneType], required=False, default=None)}¶
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.
- type: str | LazySettingReference | LazyServiceReference | Sequence[str | LazySettingReference | LazyServiceReference] | None¶
service type, aka the implementation we are using, if different from base
- class ServiceDefinitionCollection[source]¶
Bases:
BaseServiceDefinitionCollection
Final class for a service collection. Iterate on it to get a flattened (one level) and merged (services with same name that allows overrides are merged together) list of services.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- 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]] = {'services': FieldInfo(annotation=Sequence[Annotated[Union[Annotated[ServiceDefinition, Tag], Annotated[BaseServiceDefinitionCollection, Tag], Annotated[ConditionalServiceDefinitionCollection, Tag]], Discriminator]], 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.