Skip to content

Services

A service in Wireup is any class or function decorated with @service. Services can live anywhere but must be registered with the container.

For information about registering services, see the Container documentation.

Class Services

The simplest way to define a service is with a class:

from wireup import service

@service
class VehicleRepository: ...

@service
class RentalService:
    # VehicleRepository is automatically injected
    def __init__(self, repository: VehicleRepository) -> None: ...

Factory Services

For complex initialization logic or resource management, wireup supports factories that can handle setup and cleanup operations. See the Factory Functions documentation for detailed information on creating and using factory services.

Dependency Resolution

Wireup uses type annotations to resolve dependencies. Factory name and parameter names are for readability only.

# These are equivalent:
@service
def rental_service_factory(repo: VehicleRepository) -> RentalService:
    return RentalService(repo)

@service
def make_rental_service(vehicle_store: VehicleRepository) -> RentalService:
    return RentalService(vehicle_store)