Skip to content

Latest commit

 

History

History
93 lines (83 loc) · 2.25 KB

README.md

File metadata and controls

93 lines (83 loc) · 2.25 KB

Penta Quark Modules (not supported!)

Build Status Coverage Status License

Penta Quark Modules allows modules to register automatically, everything you need to inherit from one of the PentaQuarkModule or AutoPentaQuarkModule classes

Depending on the class with which you inherit, modules can register themselves in ktor

Usage

Maven

<dependency>
  <groupId>dev.talosdx</groupId>
  <artifactId>pentaquark-modules</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

Groovy

implementation 'dev.talosdx:pentaquark-modules:1.0.0'

Kotlin DSL

implementation("dev.talosdx:pentaquark-modules:1.0.0")

Prepare for use pq modules

fun main(args : Array<String>) {
    embeddedServer(Netty, 8080) {
        pentaQuarkModules { 
            //register all auto pq modules with tag "auto" 
            enableModules()
        }
    }.start()
}

Or you can use another way by registering the module with the extension function

fun Application.initPqModule() {
    pentaQuarkModules {
        //register all auto pq modules with tag "auto" 
        enableModules()
    }
}

and add ext fun to application.conf

Or just add this to application.conf

ktor {
  application {
    modules = [
      dev.talosdx.pentaquark.modules.InitPqModuleKt.initPqModule
    ]
  }
}

Example usage pq modules

Example 1

class ExampleController() : AutoPentaQuarkModule() {
    override val moduleConfig: Application.() -> Unit
        get() = {
            consoleLog()
        }

    private fun consoleLog() {
        print("something")
    }
}

Example 2

class ExampleController(service: ExampleService) : AutoPentaQuarkModule({
    routing {
        get("/consolelog") {
            service.consoleLog()
        }
    }
})

class ExampleService {
    fun consoleLog() {
        print("something")
    }
}