Service

class moxie.core.service.ProviderService(providers={})

Used where a Service deals with many external providers. Example usage can be found in the TransportService

get_provider(doc, *args, **kwargs)

Returns a Provider which can handle your doc.

If no (single) approrpriate provider can be found for your document we raise a ProviderException. Two subclasses are currently raised:

  • NoSuitableProviderFound if we can’t find any provider.
  • MultipleProvidersFound if we find more than one provider.
class moxie.core.service.Service

Services are HTTP (transport layer) agnostic instead operating at the Application Layer. Services encapsulate all operations made on the data. Views should never directly access data sources without going through a Service.

Configuration of services can be done for each Blueprint. Within the Application context they will be cached, this means the following code accesses the same Service object.:

with app.app_context():
    service_one = MyService.from_context()
    service_two = MyService.from_context()
    assert(service_one is service_two)
classmethod from_context(blueprint_name='')

Create a Service from the application and request context. args and kwargs for the Service are read from the Flask.config. Configuration should follow this pattern:

SERVICES = {
    'my_blueprint': {
        'MyService': (args, kwargs),
        'MySecondService: ((1,2,3), {'foo': 'bar'},
        }
    }
Parameters:blueprint_name – Override the blueprint name so it isn’t read from the request context.