Skip to content

Commit

Permalink
Rename classes that should not be pluralised
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwyatt committed Mar 17, 2024
1 parent 2ab77fa commit c2365f1
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.connorwyatt.common.eventstore.aggregates

import com.github.connorwyatt.common.eventstore.events.EventsRepository
import com.github.connorwyatt.common.eventstore.events.EventRepository
import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor
import kotlin.reflect.KClass

class AggregatesRepository(
private val eventsRepository: EventsRepository,
class AggregateRepository(
private val eventRepository: EventRepository,
private val aggregateMap: AggregateMap
) {
suspend fun <TAggregate : Aggregate> load(clazz: KClass<TAggregate>, id: String): TAggregate {
Expand All @@ -14,7 +14,7 @@ class AggregatesRepository(

val aggregate = constructor.invoke(id)

val events = eventsRepository.readStream(streamDescriptor)
val events = eventRepository.readStream(streamDescriptor)

aggregate.applyEvents(events)

Expand All @@ -34,7 +34,7 @@ class AggregatesRepository(

val streamDescriptor = StreamDescriptor.Origin(category, aggregate.id)

eventsRepository.appendToStream(
eventRepository.appendToStream(
streamDescriptor,
aggregate.unsavedEvents,
aggregate.latestSavedEventVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import com.eventstore.dbclient.SubscribeToStreamOptions
import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper
import com.github.connorwyatt.common.eventstore.events.ResolvedEventMapper
import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

class EventStoreSubscriptionsManager(
class EventStoreSubscriptionManager(
private val eventStoreClientWrapper: EventStoreClientWrapper,
private val eventHandlers: Set<EventHandler>,
private val eventHandlerMap: EventHandlerMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.connorwyatt.common.eventstore.events

import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor

interface EventsRepository {
interface EventRepository {
suspend fun readStream(streamDescriptor: StreamDescriptor): List<EventEnvelope<out Event>>

suspend fun appendToStream(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import com.eventstore.dbclient.ReadStreamOptions
import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper
import com.github.connorwyatt.common.eventstore.streams.StreamDescriptor

class EventStoreEventsRepository(
class EventStoreEventRepository(
private val eventStoreClient: EventStoreClientWrapper,
private val eventMap: EventMap,
private val resolvedEventMapper: ResolvedEventMapper
) : EventsRepository {
) : EventRepository {
override suspend fun readStream(
streamDescriptor: StreamDescriptor
): List<EventEnvelope<out Event>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.time.withTimeout

class InMemoryEventsRepository(
class InMemoryEventRepository(
private val clock: Clock,
private val eventMap: EventMap,
private val eventHandlerMap: EventHandlerMap,
private val eventHandlers: Set<EventHandler>,
) : EventsRepository {
) : EventRepository {
private var streams = emptyMap<StreamDescriptor, List<EventEnvelope<out Event>>>()
private val streamUpdateMutex = Mutex()
private val eventPropagationCoroutineScope = CoroutineScope(Dispatchers.Default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import com.github.connorwyatt.common.eventstore.EventStoreClientWrapper
import com.github.connorwyatt.common.eventstore.aggregates.Aggregate
import com.github.connorwyatt.common.eventstore.aggregates.AggregateMap
import com.github.connorwyatt.common.eventstore.aggregates.AggregateMapDefinition
import com.github.connorwyatt.common.eventstore.aggregates.AggregatesRepository
import com.github.connorwyatt.common.eventstore.aggregates.AggregateRepository
import com.github.connorwyatt.common.eventstore.configuration.EventStoreConfiguration
import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandler
import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerDefinition
import com.github.connorwyatt.common.eventstore.eventhandlers.EventHandlerMap
import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager
import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionManager
import com.github.connorwyatt.common.eventstore.events.EventMap
import com.github.connorwyatt.common.eventstore.events.EventMapDefinition
import com.github.connorwyatt.common.eventstore.events.EventStoreEventsRepository
import com.github.connorwyatt.common.eventstore.events.EventsRepository
import com.github.connorwyatt.common.eventstore.events.InMemoryEventsRepository
import com.github.connorwyatt.common.eventstore.events.EventRepository
import com.github.connorwyatt.common.eventstore.events.EventStoreEventRepository
import com.github.connorwyatt.common.eventstore.events.InMemoryEventRepository
import com.github.connorwyatt.common.eventstore.events.ResolvedEventMapper
import org.kodein.di.DI
import org.kodein.di.bindProvider
Expand All @@ -28,12 +28,12 @@ import org.kodein.di.new

fun eventStoreDependenciesModule(eventStoreConfiguration: EventStoreConfiguration): DI.Module =
DI.Module(name = ::eventStoreDependenciesModule.name) {
bindSingletonOf(::AggregatesRepository)
bindSingletonOf(::AggregateRepository)
bindSingletonOf(::AggregateMap)
bindSet<AggregateMapDefinition<Aggregate>>()

if (!eventStoreConfiguration.useInMemoryEventStore) {
bindProvider<EventsRepository> { new(::EventStoreEventsRepository) }
bindProvider<EventRepository> { new(::EventStoreEventRepository) }
bindSingleton<EventStoreDBClient> {
val settings =
EventStoreDBConnectionString.parseOrThrow(
Expand All @@ -44,10 +44,10 @@ fun eventStoreDependenciesModule(eventStoreConfiguration: EventStoreConfiguratio
EventStoreDBClient.create(settings)
}
bindProviderOf(::EventStoreClientWrapper)
bindSingletonOf(::EventStoreSubscriptionsManager)
bindSingletonOf(::EventStoreSubscriptionManager)
bindProviderOf(::ResolvedEventMapper)
} else {
bindSingleton<EventsRepository> { new(::InMemoryEventsRepository) }
bindSingleton<EventRepository> { new(::InMemoryEventRepository) }
}

bindSingletonOf(::EventMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.github.connorwyatt.common.eventstore.ktor

import com.github.connorwyatt.common.eventstore.configuration.EventStoreConfiguration
import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionsManager
import com.github.connorwyatt.common.eventstore.events.EventsRepository
import com.github.connorwyatt.common.eventstore.events.InMemoryEventsRepository
import com.github.connorwyatt.common.eventstore.eventhandlers.EventStoreSubscriptionManager
import com.github.connorwyatt.common.eventstore.events.EventRepository
import com.github.connorwyatt.common.eventstore.events.InMemoryEventRepository
import io.ktor.server.application.*
import org.kodein.di.instance
import org.kodein.di.ktor.closestDI

fun Application.configureEventStore(eventStoreConfiguration: EventStoreConfiguration) {
if (!eventStoreConfiguration.useInMemoryEventStore) {
val eventStoreSubscriptionsManager by closestDI().instance<EventStoreSubscriptionsManager>()
val eventStoreSubscriptionManager by closestDI().instance<EventStoreSubscriptionManager>()

eventStoreSubscriptionsManager.start()
eventStoreSubscriptionManager.start()
}

val eventsRepository by closestDI().instance<EventsRepository>()
val eventRepository by closestDI().instance<EventRepository>()

(eventsRepository as? InMemoryEventsRepository)?.run { startEventPropagation() }
(eventRepository as? InMemoryEventRepository)?.run { startEventPropagation() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.json.Json
import kotlinx.serialization.serializer

internal class RabbitMQSubscriptionsManager(
internal class RabbitMQSubscriptionManager(
private val exchangeName: String,
private val connection: Connection,
private val commandQueueList: CommandQueueList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.github.connorwyatt.common.rabbitmq.bus.RabbitMQCommandBus
import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerDefinition
import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerMap
import com.github.connorwyatt.common.rabbitmq.commandhandlers.CommandHandlerRouter
import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager
import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionManager
import com.github.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration
import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueCreator
import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueDefinition
Expand Down Expand Up @@ -41,7 +41,7 @@ fun rabbitMQDependenciesModule(rabbitMQConfiguration: RabbitMQConfiguration): DI
}

bindSingleton {
RabbitMQSubscriptionsManager(
RabbitMQSubscriptionManager(
rabbitMQConfiguration.exchangeName,
instance(),
instance(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.github.connorwyatt.common.rabbitmq.ktor

import com.github.connorwyatt.common.rabbitmq.bus.CommandBus
import com.github.connorwyatt.common.rabbitmq.bus.InMemoryCommandBus
import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionsManager
import com.github.connorwyatt.common.rabbitmq.commandhandlers.RabbitMQSubscriptionManager
import com.github.connorwyatt.common.rabbitmq.configuration.RabbitMQConfiguration
import com.github.connorwyatt.common.rabbitmq.queues.CommandQueueCreator
import io.ktor.server.application.*
Expand All @@ -17,8 +17,8 @@ fun Application.configureRabbitMQ(rabbitMQConfiguration: RabbitMQConfiguration)
commandQueueCreator.createQueues()

if (!rabbitMQConfiguration.useInMemoryRabbitMQ) {
val rabbitMQSubscriptionsManager by closestDI().instance<RabbitMQSubscriptionsManager>()
rabbitMQSubscriptionsManager.start()
val rabbitMQSubscriptionManager by closestDI().instance<RabbitMQSubscriptionManager>()
rabbitMQSubscriptionManager.start()
}

val commandBus by closestDI().instance<CommandBus>()
Expand Down

0 comments on commit c2365f1

Please sign in to comment.