diff --git a/docs/index.md b/docs/index.md index 4622c7e..9bce6f4 100644 --- a/docs/index.md +++ b/docs/index.md @@ -5,30 +5,27 @@ Mediator implementation for Kotlin. ## Usage ```diff -+ $version = 3.0.0 ++ $version = 3.1.1 ```
Gradle -To use the SNAPSHOT version you need to add repository to your dependency management: - -```kotlin - maven { - url = uri("https://oss.sonatype.org/content/repositories/snapshots") - } -``` - kediatR-core ```kotlin implementation("com.trendyol:kediatr-core:$version") ``` -kediatR-spring-starter +kediatR provides two different packages for spring-boot 2x and 3x. You can use the following dependencies according to +your spring-boot version. ```kotlin - implementation("com.trendyol:kediatr-spring-starter:$version") + implementation("com.trendyol:kediatr-spring-boot-2x-starter:$version") + + // or + + implementation("com.trendyol:kediatr-spring-boot-3x-starter:$version") ``` kediatR-koin-starter @@ -45,92 +42,14 @@ kediatR-quarkus-starter
-
-Maven - -To use the SNAPSHOT version you need to add repository to your dependency management: - -```xml - - - allow-snapshots - true - - - snapshots-repo - https://oss.sonatype.org/content/repositories/snapshots - false - true - - - - -``` - -kediatR-core - -```xml - - com.trendyol - kediatr-core - $version - -``` - -kediatR-spring-starter - -```xml - - com.trendyol - kediatr-spring-starter - $version - -``` - -kediatR-koin-starter - -```xml - - com.trendyol - kediatr-koin-starter - $version - -``` - -kediatR-quarkus-starter - -```xml - - com.trendyol - kediatr-quarkus-starter - $version - -``` - -
- ### Command dispatching ```kotlin -class ManualDependencyProvider( - private val handlerMap: HashMap, Any> -) : DependencyProvider { - override fun getSingleInstanceOf(clazz: Class): T { - return handlerMap[clazz] as T - } - - override fun getSubTypesOf(clazz: Class): Collection> { - return handlerMap - .filter { it.key.interfaces.contains(clazz) } - .map { it.key as Class } - } -} +import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator fun main() { val handler = HelloCommandHandler() - val handlers: HashMap, Any> = hashMapOf(Pair(HelloCommandHandler::class.java, handler)) - val provider = ManualDependencyProvider(handlers) - val mediator: Mediator = MediatorBuilder(provider).build() + val mediator: Mediator = createMediator(handlers = listOf(handler)) mediator.send(HelloCommand("hello")) } @@ -141,18 +60,16 @@ class HelloCommandHandler : CommandHandler { println(command.message) } } - ``` ### Query dispatching ```kotlin +import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator fun main() { val handler = GetSomeDataQueryHandler() - val handlers: HashMap, Any> = hashMapOf(Pair(GetSomeDataQuery::class.java, handler)) - val provider = ManualDependencyProvider(handlers) - val mediator: Mediator = MediatorBuilder(provider).build() + val mediator: Mediator = createMediator(handlers = listOf(handler)) val result: String = mediator.send(GetSomeDataQuery(1)) println(result) } @@ -174,6 +91,9 @@ class GetSomeDataQueryHandler : QueryHandler { ```kotlin class CommandProcessingPipeline : PipelineBehavior { + + override val order: Int = 1 + override suspend fun handle( request: TRequest, next: RequestHandlerDelegate @@ -191,7 +111,6 @@ class CommandProcessingPipeline : PipelineBehavior { * Add _kediatr-spring_ dependency to your maven or gradle dependencies ```kotlin - @Service class UserService(private val mediator: Mediator) { suspend fun findUser(id: Long) { @@ -240,7 +159,6 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer return UserDto(user.id, user.name, user.surname) } } - ``` ## Quarkus @@ -255,10 +173,7 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer kediatr: group-id: com.trendyol artifact-id: kediatr-quarkus-starter - ``` - -* Add @Startup annotation for every handler so that KediatR can prepare queries and commands on beginning of the - application. +``` ```kotlin class UserService(private val mediator: mediator) { @@ -270,7 +185,6 @@ class UserService(private val mediator: mediator) { class GetUserByIdQuery(private val id: Long) : Query @ApplicationScoped -@Startup class GetUserByIdQueryHandler(private val userRepository: UserRepository) : QueryHandler { override suspend fun handle(query: GetUserByIdQuery): UserDto { val user = userRepository.findById(query.id) @@ -278,12 +192,9 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer return UserDto(user.id, user.name, user.surname) } } - ``` -## Review Our IntelliJ Plugin - -### Warning: This plugin does not support v2.0+ yet. +## Check Our IntelliJ Plugin