All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.trendyol.kediatr.RegistryImpl.kt Maven / Gradle / Ivy

@file:Suppress("UNCHECKED_CAST")

package com.trendyol.kediatr

class RegistryImpl(
  dependencyProvider: DependencyProvider
) : Registry {
  private val registry = Container(dependencyProvider)

  override fun  resolveCommandHandler(classOfCommand: Class): CommandHandler {
    val handler =
      registry.commandMap[classOfCommand]?.get()
        ?: throw HandlerNotFoundException("handler could not be found for ${classOfCommand.name}")
    return handler as CommandHandler
  }

  override fun , TResult> resolveCommandWithResultHandler(
    classOfCommand: Class
  ): CommandWithResultHandler {
    val handler =
      registry.commandWithResultMap[classOfCommand]?.get()
        ?: throw HandlerNotFoundException("handler could not be found for ${classOfCommand.name}")
    return handler as CommandWithResultHandler
  }

  override fun  resolveNotificationHandlers(
    classOfNotification: Class
  ): Collection> =
    registry.notificationMap.filter { (k, _) -> k.isAssignableFrom(classOfNotification) }
      .flatMap { (_, v) -> v.map { it.get() as NotificationHandler } }

  override fun , TResult> resolveQueryHandler(classOfQuery: Class): QueryHandler {
    val handler =
      registry.queryMap[classOfQuery]?.get()
        ?: throw HandlerNotFoundException("handler could not be found for ${classOfQuery.name}")
    return handler as QueryHandler
  }

  override fun getPipelineBehaviors(): Collection = registry.pipelineSet.map { it.get() }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy