mirror of
https://github.com/InsanusMokrassar/docs.git
synced 2024-12-26 18:47:28 +00:00
add micro_utils startup docs
This commit is contained in:
parent
9ec30af2ad
commit
df2812a04d
65
docs/micro_utils/startup.md
Normal file
65
docs/micro_utils/startup.md
Normal file
@ -0,0 +1,65 @@
|
||||
# Startup [![Maven Central](https://img.shields.io/maven-central/v/dev.inmo/micro_utils.common?label=latest_version&style=flat-square)](https://github.com/InsanusMokrassar/MicroUtils)
|
||||
|
||||
* **Plugins Package**: `dev.inmo:micro_utils.startup.plugin`
|
||||
* **Launcher Package**: `dev.inmo:micro_utils.startup.launcher`
|
||||
|
||||
This package contains unified simple `Plugin`/`Launcher` tools for separating of your apps parts
|
||||
|
||||
## Plugin
|
||||
|
||||
To define plugin, you must use `StartPlugin` as supertype for your plugin. Restrictions are simple: plugins must be an `object` or `class` with empty constructor. Basic sample is here:
|
||||
|
||||
```kotlin
|
||||
object YourPlugin : StartPlugin {
|
||||
// Body of your plugin
|
||||
}
|
||||
```
|
||||
|
||||
Each plugin may contains to parts:
|
||||
|
||||
* `setupDI` function to set up DI part
|
||||
* `startPlugin` function to start plugin
|
||||
|
||||
```kotlin
|
||||
object YourPlugin : StartPlugin {
|
||||
override fun Module.setupDI(config: JsonObject) {
|
||||
// here you may setup any DI content you wish to be available in context of current Koin module
|
||||
}
|
||||
override fun startPlugin(koin: Koin) {
|
||||
// all staff from setupDI and the same function of other plugins is available in koin
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Launcher
|
||||
|
||||
Basically, launcher module can be used to start application directly from `gradle`. Let's imagine you have this gradle groovy config:
|
||||
|
||||
```groovy
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm'
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id 'application'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// kotlin and other dependencies
|
||||
implementation ("dev.inmo:micro_utils.startup.launcher:$latest_version")
|
||||
}
|
||||
|
||||
application {
|
||||
mainClassName = 'dev.inmo.micro_utils.startup.launcher.MainKt'
|
||||
}
|
||||
```
|
||||
|
||||
You will be able to run your project with gradle command `./gradlew run --args="path/to/config.json"`. `config.json` must contains something like:
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": [
|
||||
"dev.inmo.micro_utils.startup.launcher.HelloWorldPlugin"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
In current case you will see in logger different logs about launching including log from `HelloWorldPlugin` with text `Hello world`.
|
@ -11,6 +11,7 @@ nav:
|
||||
- 'MicroUtils':
|
||||
- 'micro_utils/index.md'
|
||||
- 'micro_utils/resources.md'
|
||||
- 'micro_utils/startup.md'
|
||||
- 'Telegram Bot API':
|
||||
- 'tgbotapi/index.md'
|
||||
- KDocs: 'https://tgbotapi.inmo.dev'
|
||||
|
Loading…
Reference in New Issue
Block a user