Exposing services through plugins
Some plugins need to provide users with helper methods to simplify transactions, whereas others need not do anything besides some tasks to be added in the application's life cycle. For example, our NotifierPlugin
just sends e-mails on start and stop. Then, the methods of our CassandraPlugin
can be accessed using the plugin
method of play.api.Application
:
object CassandraHelper {
private val casPlugin = Play.application.plugin[CassandraPlugin].get
//complete DB transactions with the connection pool started through the plugin
def executeStmt(stmt:String) = {
casPlugin.session.execute(stmt)
}
}
Alternatively, the plugin can also provide a helper object:
object Cassandra { private val casPlugin = Play.application.plugin[CassandraPlugin].get private val cassandraHelper = casPlugin.helper /** * gets the Cassandra hosts provided in the configuration */ def hosts: Array[java.lang.String] = cassandraHelper.hosts /** * gets...