(Quick Reference)

8.2.2 Service Configuration DSL - Reference Documentation

Authors: Andres Almiray

Version: 1.2.0

8.2.2 Service Configuration DSL

Services may have some of its properties defined in external configuration files, for example in Config.groovy, using a simple DSL. Take for example the following service class

class NetworkService {
    String host
    int port
    private Server server

void connect() { if (!server) { server = new Server(host, port) } } }

This service declares 2 public properties (host and port) but does not define any values for them. Inside Config.groovy we find the following definitions

services {
    network {
        host = 'http://acme.com'
        port = 1234
    }
}

The rules are simple to understand given this example.

  • The entry point is the top services section.
  • Each child node identifies the target service by name. Notice that the Service suffix is omitted.
  • Each property within a service block will be set on the service instance.