Service container¶
The built-in backend classes also implement the service container in order to simplify the binding process:
Source code in combadge/core/backend.py
__getitem__ ¶
Bind the protocol to the current backend and return the service instance.
This method caches the service instances, and so may be used repeatedly without a performance impact.
Examples:
>>> class ServiceProtocolA(Protocol): ...
>>> class ServiceProtocolB(Protocol): ...
>>>
>>> backend = HttpxBackend()
>>>
>>> service_a = backend[ServiceProtocolA]
>>> service_b = backend[ServiceProtocolB]
Source code in combadge/core/backend.py
__delitem__ ¶
Delete the cached service instance for the specified protocol.
This operation is idempotent
It is safe to remove a non-existing service instance.