-
-
Notifications
You must be signed in to change notification settings - Fork 953
Artifact Namespaces
Up through Grails 2.1.x we have no good way of managing artifact conflicts. Artifact conflicts include things like controllers or services with the same name in separate packages. For example an application may not contain both com.demo.UserController
and com.demo.admin.UserController
. Within an application this can be managed by simply naming them differently. The bigger problem comes from using multiple plugins that provide artifacts with the same name.
We should identify places where the plugin name may be used effectively as a namespace for artifacts. All places where artifact names are used are candidates for attention.
When referring to a controller from a tag like g:link
, specifying a plugin name may disambiguate the reference:
<g:link controller="user" plugin="spring-security">Manage Users</g:link>
Methods that support a controller name in the form of a named argument should support a plugin name.
class DemoController {
def index() {
redirect controller: 'user', action: 'list', plugin: 'spring-security'
}
}
Instances of Service artifacts are automatically added to the spring application context. The bean name is derived from the class name so an instance of com.demo.admin.UserService
is added to the application context with the bean name userService
. For services provided by a plugin then bean name may be prefixed with a camel case version of the plugin name. For example, if the spring-security
plugin provides com.demo.admin.UserService
then the bean name would be springSecurityUserService
. It may be beneficial to alias the bean to userService
if and only if there is no other UserService
service anywhere in the application.
The default name of the table that domain classes are associated with is derived from the domain class name so a com.demo.GuitarAmplifier
domain class is associated with a GUITAR_AMPLIFIER
table. The default table name could be prefixed with the plugin name. For example, if the music-equipment
plugin provides com.demo.GuitarAmplifier
, the default table name could be MUSIC_EQUIPMENT_GUITAR_AMPLIFIER
.