Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Oct 30, 2024
1 parent 94090d9 commit 293e60f
Showing 1 changed file with 17 additions and 106 deletions.
123 changes: 17 additions & 106 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@ Mediator implementation for Kotlin.
## Usage

```diff
+ $version = 3.0.0
+ $version = 3.1.1
```

<details open>
<summary>Gradle</summary>

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
Expand All @@ -45,92 +42,14 @@ kediatR-quarkus-starter

</details>

<details>
<summary>Maven</summary>

To use the SNAPSHOT version you need to add repository to your dependency management:

```xml
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
```

kediatR-core

```xml
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-core</artifactId>
<version>$version</version>
</dependency>
```

kediatR-spring-starter

```xml
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-spring-starter</artifactId>
<version>$version</version>
</dependency>
```

kediatR-koin-starter

```xml
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-koin-starter</artifactId>
<version>$version</version>
</dependency>
```

kediatR-quarkus-starter

```xml
<dependency>
<groupId>com.trendyol</groupId>
<artifactId>kediatr-quarkus-starter</artifactId>
<version>$version</version>
</dependency>
```

</details>

### Command dispatching

```kotlin
class ManualDependencyProvider(
private val handlerMap: HashMap<Class<*>, Any>
) : DependencyProvider {
override fun <T> getSingleInstanceOf(clazz: Class<T>): T {
return handlerMap[clazz] as T
}

override fun <T> getSubTypesOf(clazz: Class<T>): Collection<Class<T>> {
return handlerMap
.filter { it.key.interfaces.contains(clazz) }
.map { it.key as Class<T> }
}
}
import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator

fun main() {
val handler = HelloCommandHandler()
val handlers: HashMap<Class<*>, 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"))
}

Expand All @@ -141,18 +60,16 @@ class HelloCommandHandler : CommandHandler<HelloCommand> {
println(command.message)
}
}

```

### Query dispatching

```kotlin
import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator

fun main() {
val handler = GetSomeDataQueryHandler()
val handlers: HashMap<Class<*>, 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)
}
Expand All @@ -174,6 +91,9 @@ class GetSomeDataQueryHandler : QueryHandler<GetSomeDataQuery, String> {

```kotlin
class CommandProcessingPipeline : PipelineBehavior {

override val order: Int = 1

override suspend fun <TRequest, TResponse> handle(
request: TRequest,
next: RequestHandlerDelegate<TRequest, TResponse>
Expand All @@ -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) {
Expand Down Expand Up @@ -240,7 +159,6 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer
return UserDto(user.id, user.name, user.surname)
}
}

```

## Quarkus
Expand All @@ -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) {
Expand All @@ -270,20 +185,16 @@ class UserService(private val mediator: mediator) {
class GetUserByIdQuery(private val id: Long) : Query<UserDto>

@ApplicationScoped
@Startup
class GetUserByIdQueryHandler(private val userRepository: UserRepository) : QueryHandler<GetUserByIdQuery, UserDto> {
override suspend fun handle(query: GetUserByIdQuery): UserDto {
val user = userRepository.findById(query.id)
// do some operation on user
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

<https://plugins.jetbrains.com/plugin/16017-kediatr-helper>

Expand Down

0 comments on commit 293e60f

Please sign in to comment.