Service container¶
The built-in backend classes also implement the service container in order to simplify the binding process:
Abstract base backend class.
- It provides an entry point for binding a service method to the backend.
- It also caches all the service instances bound to the backend via the item protocol.
Source code in combadge/core/backend.py
bind_method
abstractmethod
classmethod
¶
Bind the method by its signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signature
|
Signature
|
extracted method signature |
required |
Returns:
Type | Description |
---|---|
ServiceMethod[Self]
|
Callable service method which is fully capable of sending a request and receiving a response |
ServiceMethod[Self]
|
via this backend. |
Source code in combadge/core/backend.py
__getitem__ ¶
Bind the given protocol to this backend and return the bound service instance.
This method caches the service instances, and so may be used repeatedly without a huge 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.