Griffon
  1. Griffon
  2. GRIFFON-565

Allow service properties to be configured externally

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1.0
    • Fix Version/s: 1.2.0
    • Component/s: rt
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Based on a discussion started at the mailing list, it would be great if service properties could be specified in an external configuration file, probably using a DSL.

      Currently it's possible to build your own "service config injector" by relying on application events. Say for example you have a service defined like so

          class NetworkService {
              int port
              void connect() { /* use port property here */ }
          }
      

      You could define configuration for this service in Config.groovy like this

          services {
              networkService {
                  port = 5050
              }
          }
      

      Injecting this value is done using an application event handler registered for NewInstance, typically in Events.groovy

          onNewInstance = { klass, type, instance ->
              if (type != 'service') return
              String serviceName = GriffonNameUtils.getPropertyName(klass)
              ConfigObject config = ApplicationHolder.application.config.services[serviceName]
              config.each { key, value -> instance[key] = value }
          }
      

        Activity

        Show
        Andres Almiray added a comment - Fixed with https://github.com/griffon/griffon/commit/4949284439a6b439c0e815d21c76c8e1791a11e3

          People

          • Assignee:
            Andres Almiray
            Reporter:
            Andres Almiray
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: