Skip to content

Service factory

pems_data.ServiceFactory

A factory class to create and configure various services.

Shared dependencies are created once during initialization.

Source code in pems_data/__init__.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class ServiceFactory:
    """
    A factory class to create and configure various services.

    Shared dependencies are created once during initialization.
    """

    @property
    def cache(self) -> Cache:
        """
        Returns:
            value (pems_data.cache.Cache): The shared Cache instance managed by this factory.
        """
        return self._cache

    @property
    def s3_source(self) -> S3DataSource:
        """
        Returns:
            value (pems_data.sources.s3.S3DataSource): The shared S3DataSource instance managed by this factory.
        """
        return self._s3_source

    @property
    def caching_s3_source(self) -> CachingDataSource:
        """
        Returns:
            value (pems_data.sources.cache.CachingDataSource): The shared CachingDataSource instance managed by this factory.
        """
        return self._caching_s3_source

    def __init__(self):
        """Initializes a new ServiceFactory and shared dependencies."""
        self._cache = Cache()
        self._s3_source = S3DataSource()
        self._caching_s3_source = CachingDataSource(data_source=self._s3_source, cache=self._cache)

    def stations_service(self) -> StationsService:
        """Creates a fully-configured StationsService.

        Returns:
            value (pems_data.services.stations.StationsService): A StationsService instance configured by the factory.
        """
        return StationsService(data_source=self._caching_s3_source)

cache property

Returns:

Name Type Description
value Cache

The shared Cache instance managed by this factory.

caching_s3_source property

Returns:

Name Type Description
value CachingDataSource

The shared CachingDataSource instance managed by this factory.

s3_source property

Returns:

Name Type Description
value S3DataSource

The shared S3DataSource instance managed by this factory.

__init__()

Initializes a new ServiceFactory and shared dependencies.

Source code in pems_data/__init__.py
38
39
40
41
42
def __init__(self):
    """Initializes a new ServiceFactory and shared dependencies."""
    self._cache = Cache()
    self._s3_source = S3DataSource()
    self._caching_s3_source = CachingDataSource(data_source=self._s3_source, cache=self._cache)

stations_service()

Creates a fully-configured StationsService.

Returns:

Name Type Description
value StationsService

A StationsService instance configured by the factory.

Source code in pems_data/__init__.py
44
45
46
47
48
49
50
def stations_service(self) -> StationsService:
    """Creates a fully-configured StationsService.

    Returns:
        value (pems_data.services.stations.StationsService): A StationsService instance configured by the factory.
    """
    return StationsService(data_source=self._caching_s3_source)