Grails Services

Services

Grails Service uses to separate your business logic from the other layer or component. Services are named in the format SomeNameService.groovy and placed in the directory /grails-app/services/. Services can make use of dependency injection features, and you can easily call these services from within controllers.

Class SearchableService {
Booleab transactional =true
def compass
def compassGps
def searchableMethodFactory
def search (Object[] args){
searcgableMethodFactory.getMethod(“searcg”).invoke(*args)
}

Above depicts the SearchableService

SearchableService (stored in grailsapp/services) got added to the SearchableController automatically using single line def searchableService right after the class declaration of the Controller. This is the way Grails uses dependency injection, or “DI” for short. Unit Testing Controllers

Plug-in

Grails plugins are like JARs on steroids. They can include not only one or more JARs, but also GSPs, Controllers, TagLibs, Codecs, and more. In essence, they are mini Grails applications expressly meant to be merged with other Grails applications.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s