Providers & Services¶
A generic framework for service providers, recommended to be used whenever there are multiple ways of accomplishing a task or multiple sources can offer the required data.
-
xl.providers.
MANAGER
¶ Singleton instance of the
ProviderManager
-
xl.providers.
register
(servicename, provider, target=None)¶ Registers a provider for a service. The provider object is used by consumers of the service.
Services can be targeted for a specific use. For example, if you have a widget that uses a service ‘foo’, if your object can perform a service only for a specific type of widget, then target would be set to the widget type.
If you had a service that could perform ‘foo’ for all widgets, then target would be set to None, and all widgets could use your service.
It is intended that most services should set target to None, with some narrow exceptions.
Parameters:
-
xl.providers.
unregister
(servicename, provider, target=None)¶ Unregisters a provider.
Parameters:
-
xl.providers.
get
(servicename, target=None)¶ Returns a list of providers for the specified servicename.
This will return providers targeted for a specific target AND providers not targeted towards any particular target.
Parameters: - servicename (string) – the service name to get providers for
- target (object) – the target of the service
Returns: list of providers
Return type: list of objects
-
xl.providers.
get_provider
(servicename, providername, target=None)¶ Returns a single identified provider
This will return a provider either targeted for the specific target or a provider not targeted towards any particular target.
Parameters: - servicename (string) – The service name to get the provider for
- providername (string) – The provider name to identify the provider
- target (object) – the target of the service
Returns: a provider or None
Return type: