Skip to content

Commit 293e60f

Browse files
committed
update docs
1 parent 94090d9 commit 293e60f

File tree

1 file changed

+17
-106
lines changed

1 file changed

+17
-106
lines changed

docs/index.md

Lines changed: 17 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@ Mediator implementation for Kotlin.
55
## Usage
66

77
```diff
8-
+ $version = 3.0.0
8+
+ $version = 3.1.1
99
```
1010

1111
<details open>
1212
<summary>Gradle</summary>
1313

14-
To use the SNAPSHOT version you need to add repository to your dependency management:
15-
16-
```kotlin
17-
maven {
18-
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
19-
}
20-
```
21-
2214
kediatR-core
2315

2416
```kotlin
2517
implementation("com.trendyol:kediatr-core:$version")
2618
```
2719

28-
kediatR-spring-starter
20+
kediatR provides two different packages for spring-boot 2x and 3x. You can use the following dependencies according to
21+
your spring-boot version.
2922

3023
```kotlin
31-
implementation("com.trendyol:kediatr-spring-starter:$version")
24+
implementation("com.trendyol:kediatr-spring-boot-2x-starter:$version")
25+
26+
// or
27+
28+
implementation("com.trendyol:kediatr-spring-boot-3x-starter:$version")
3229
```
3330

3431
kediatR-koin-starter
@@ -45,92 +42,14 @@ kediatR-quarkus-starter
4542

4643
</details>
4744

48-
<details>
49-
<summary>Maven</summary>
50-
51-
To use the SNAPSHOT version you need to add repository to your dependency management:
52-
53-
```xml
54-
<profiles>
55-
<profile>
56-
<id>allow-snapshots</id>
57-
<activation><activeByDefault>true</activeByDefault></activation>
58-
<repositories>
59-
<repository>
60-
<id>snapshots-repo</id>
61-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
62-
<releases><enabled>false</enabled></releases>
63-
<snapshots><enabled>true</enabled></snapshots>
64-
</repository>
65-
</repositories>
66-
</profile>
67-
</profiles>
68-
```
69-
70-
kediatR-core
71-
72-
```xml
73-
<dependency>
74-
<groupId>com.trendyol</groupId>
75-
<artifactId>kediatr-core</artifactId>
76-
<version>$version</version>
77-
</dependency>
78-
```
79-
80-
kediatR-spring-starter
81-
82-
```xml
83-
<dependency>
84-
<groupId>com.trendyol</groupId>
85-
<artifactId>kediatr-spring-starter</artifactId>
86-
<version>$version</version>
87-
</dependency>
88-
```
89-
90-
kediatR-koin-starter
91-
92-
```xml
93-
<dependency>
94-
<groupId>com.trendyol</groupId>
95-
<artifactId>kediatr-koin-starter</artifactId>
96-
<version>$version</version>
97-
</dependency>
98-
```
99-
100-
kediatR-quarkus-starter
101-
102-
```xml
103-
<dependency>
104-
<groupId>com.trendyol</groupId>
105-
<artifactId>kediatr-quarkus-starter</artifactId>
106-
<version>$version</version>
107-
</dependency>
108-
```
109-
110-
</details>
111-
11245
### Command dispatching
11346

11447
```kotlin
115-
class ManualDependencyProvider(
116-
private val handlerMap: HashMap<Class<*>, Any>
117-
) : DependencyProvider {
118-
override fun <T> getSingleInstanceOf(clazz: Class<T>): T {
119-
return handlerMap[clazz] as T
120-
}
121-
122-
override fun <T> getSubTypesOf(clazz: Class<T>): Collection<Class<T>> {
123-
return handlerMap
124-
.filter { it.key.interfaces.contains(clazz) }
125-
.map { it.key as Class<T> }
126-
}
127-
}
48+
import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator
12849

12950
fun main() {
13051
val handler = HelloCommandHandler()
131-
val handlers: HashMap<Class<*>, Any> = hashMapOf(Pair(HelloCommandHandler::class.java, handler))
132-
val provider = ManualDependencyProvider(handlers)
133-
val mediator: Mediator = MediatorBuilder(provider).build()
52+
val mediator: Mediator = createMediator(handlers = listOf(handler))
13453
mediator.send(HelloCommand("hello"))
13554
}
13655

@@ -141,18 +60,16 @@ class HelloCommandHandler : CommandHandler<HelloCommand> {
14160
println(command.message)
14261
}
14362
}
144-
14563
```
14664

14765
### Query dispatching
14866

14967
```kotlin
68+
import com.trendyol.kediatr.MappingDependencyProvider.Companion.createMediator
15069

15170
fun main() {
15271
val handler = GetSomeDataQueryHandler()
153-
val handlers: HashMap<Class<*>, Any> = hashMapOf(Pair(GetSomeDataQuery::class.java, handler))
154-
val provider = ManualDependencyProvider(handlers)
155-
val mediator: Mediator = MediatorBuilder(provider).build()
72+
val mediator: Mediator = createMediator(handlers = listOf(handler))
15673
val result: String = mediator.send(GetSomeDataQuery(1))
15774
println(result)
15875
}
@@ -174,6 +91,9 @@ class GetSomeDataQueryHandler : QueryHandler<GetSomeDataQuery, String> {
17491

17592
```kotlin
17693
class CommandProcessingPipeline : PipelineBehavior {
94+
95+
override val order: Int = 1
96+
17797
override suspend fun <TRequest, TResponse> handle(
17898
request: TRequest,
17999
next: RequestHandlerDelegate<TRequest, TResponse>
@@ -191,7 +111,6 @@ class CommandProcessingPipeline : PipelineBehavior {
191111
* Add _kediatr-spring_ dependency to your maven or gradle dependencies
192112

193113
```kotlin
194-
195114
@Service
196115
class UserService(private val mediator: Mediator) {
197116
suspend fun findUser(id: Long) {
@@ -240,7 +159,6 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer
240159
return UserDto(user.id, user.name, user.surname)
241160
}
242161
}
243-
244162
```
245163

246164
## Quarkus
@@ -255,10 +173,7 @@ class GetUserByIdQueryHandler(private val userRepository: UserRepository) : Quer
255173
kediatr:
256174
group-id: com.trendyol
257175
artifact-id: kediatr-quarkus-starter
258-
```
259-
260-
* Add @Startup annotation for every handler so that KediatR can prepare queries and commands on beginning of the
261-
application.
176+
```
262177
263178
```kotlin
264179
class UserService(private val mediator: mediator) {
@@ -270,20 +185,16 @@ class UserService(private val mediator: mediator) {
270185
class GetUserByIdQuery(private val id: Long) : Query<UserDto>
271186

272187
@ApplicationScoped
273-
@Startup
274188
class GetUserByIdQueryHandler(private val userRepository: UserRepository) : QueryHandler<GetUserByIdQuery, UserDto> {
275189
override suspend fun handle(query: GetUserByIdQuery): UserDto {
276190
val user = userRepository.findById(query.id)
277191
// do some operation on user
278192
return UserDto(user.id, user.name, user.surname)
279193
}
280194
}
281-
282195
```
283196

284-
## Review Our IntelliJ Plugin
285-
286-
### Warning: This plugin does not support v2.0+ yet.
197+
## Check Our IntelliJ Plugin
287198

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

0 commit comments

Comments
 (0)