AutoArchive._infrastructure.service

Support framework for registering and accessing services.

Modules

iservice_component

IServiceComponent interface.

class AutoArchive._infrastructure.service.iservice_component.IServiceComponent(applicationContext, serviceAccessor)[source]

Bases: object

Interface for service components.

Parameters:
  • serviceAccessor (IServiceAccessor) – Can be used to get/register services.
  • applicationContext (ApplicationContext) – Application context.
destroyServices()[source]

Destroys all services owned by this component.

iservice

IService interface.

class AutoArchive._infrastructure.service.iservice.IService[source]

Bases: object

Interface for component’s services.

See also: ServiceAccessor.

iservice_identification

IServiceIdentification interface.

class AutoArchive._infrastructure.service.iservice_identification.IServiceIdentification[source]

Bases: object

Identifies a service.

Note

Implementations should be static classes.

interface

Gets interface type of the service.

Return type:type{``object}
providerIdentificationInterface

Gets interface type for accessing information about providers of this service.

Return type:type{``object}

_service_accessor

ServiceAccessor.

class AutoArchive._infrastructure.service._service_accessor.ServiceAccessor[source]

Bases: object

Access to services.

A service can be made available by registering via this interface. Registered classes has to implement IService.

getOrCreateService(serviceIdentification, providerIdentification, *args)[source]

Provides access to registered services interfaces.

See also: registerInterface().

Parameters:
  • serviceIdentification (IServiceIdentification) – Identification of the service that shall be created.
  • providerIdentification (serviceIdentification.providerIdentificationInterface) – Corresponding service provider identification object. It should be one of the instances returned by getProvidersIdentifications(). For services with a single provider (implementation) it can be None.
  • args – Service specific arguments.
Returns:

Instance of a service provider of the particular service.

Return type:

serviceIdentification.interface

Raises KeyError:
 

If serviceIdentification is not registered.

getProvidersIdentifications(serviceIdentification)[source]

Returns providers identifications for the given service.

Parameters:serviceIdentification (IServiceIdentification) – Identification of the service.
Returns:Service providers.
Return type:iterable<serviceIdentification.providerIdentificationInterface>
Raises KeyError:
 If serviceIdentification is not registered.
registerService(serviceIdentification, providerClass, providerIdentification=None)[source]

Registers a service.

See also: unregisterService(), getOrCreateService().

Parameters:
  • serviceIdentification (IServiceIdentification) – Identification of the service that shall be registered.
  • providerClass (type{ serviceIdentification.interface, IService}) – Provider of the service.
  • providerIdentification (serviceIdentification.providerIdentificationInterface) – Corresponding service provider identification object.
Raises:
  • TypeError – If providerClass does not implement serviceIdentification.interface. If providerIdentification does not implement serviceIdentification.providerIdentificationInterface.
  • KeyError – If serviceIdentification is already registered with providerClass or providerIdentification.
unregisterService(serviceIdentification)[source]

Unregisters a service with all its providers.

All serviceType instances all destroyed first.

See also: registerService(), getOrCreateService().

Parameters:serviceIdentification (IServiceIdentification) – Identification of the service that shall be registered.
Raises KeyError:
 If serviceIdentification is not registered.
class AutoArchive._infrastructure.service._service_accessor.ServiceAccessor[source]

Bases: object

Access to services.

A service can be made available by registering via this interface. Registered classes has to implement IService.

getOrCreateService(serviceIdentification, providerIdentification, *args)[source]

Provides access to registered services interfaces.

See also: registerInterface().

Parameters:
  • serviceIdentification (IServiceIdentification) – Identification of the service that shall be created.
  • providerIdentification (serviceIdentification.providerIdentificationInterface) – Corresponding service provider identification object. It should be one of the instances returned by getProvidersIdentifications(). For services with a single provider (implementation) it can be None.
  • args – Service specific arguments.
Returns:

Instance of a service provider of the particular service.

Return type:

serviceIdentification.interface

Raises KeyError:
 

If serviceIdentification is not registered.

getProvidersIdentifications(serviceIdentification)[source]

Returns providers identifications for the given service.

Parameters:serviceIdentification (IServiceIdentification) – Identification of the service.
Returns:Service providers.
Return type:iterable<serviceIdentification.providerIdentificationInterface>
Raises KeyError:
 If serviceIdentification is not registered.
registerService(serviceIdentification, providerClass, providerIdentification=None)[source]

Registers a service.

See also: unregisterService(), getOrCreateService().

Parameters:
  • serviceIdentification (IServiceIdentification) – Identification of the service that shall be registered.
  • providerClass (type{ serviceIdentification.interface, IService}) – Provider of the service.
  • providerIdentification (serviceIdentification.providerIdentificationInterface) – Corresponding service provider identification object.
Raises:
  • TypeError – If providerClass does not implement serviceIdentification.interface. If providerIdentification does not implement serviceIdentification.providerIdentificationInterface.
  • KeyError – If serviceIdentification is already registered with providerClass or providerIdentification.
unregisterService(serviceIdentification)[source]

Unregisters a service with all its providers.

All serviceType instances all destroyed first.

See also: registerService(), getOrCreateService().

Parameters:serviceIdentification (IServiceIdentification) – Identification of the service that shall be registered.
Raises KeyError:
 If serviceIdentification is not registered.