refactor: Moved configuration in a separate class and made it more explicit
authorKai Moritz <kai@juplo.de>
Wed, 28 Dec 2022 18:20:51 +0000 (19:20 +0100)
committerKai Moritz <kai@juplo.de>
Wed, 28 Dec 2022 18:20:58 +0000 (19:20 +0100)
src/main/java/de/juplo/kafka/chat/backend/ChatBackendApplication.java
src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java [new file with mode: 0644]
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryChatroomFactory.java
src/main/java/de/juplo/kafka/chat/backend/persistence/InMemoryPersistenceStrategy.java

index f8c38b6..7f6f213 100644 (file)
@@ -10,13 +10,6 @@ import java.time.Clock;
 @SpringBootApplication
 public class ChatBackendApplication
 {
-       @Bean
-       public Clock clock()
-       {
-               return Clock.systemDefaultZone();
-       }
-
-
        public static void main(String[] args)
        {
                SpringApplication.run(ChatBackendApplication.class, args);
diff --git a/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java b/src/main/java/de/juplo/kafka/chat/backend/ChatBackendConfiguration.java
new file mode 100644 (file)
index 0000000..34036dd
--- /dev/null
@@ -0,0 +1,32 @@
+package de.juplo.kafka.chat.backend;
+
+import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
+import de.juplo.kafka.chat.backend.persistence.InMemoryChatroomFactory;
+import de.juplo.kafka.chat.backend.persistence.InMemoryPersistenceStrategy;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.time.Clock;
+
+
+@Configuration
+public class ChatBackendConfiguration
+{
+  @Bean
+  ChatroomFactory chatroomFactory(InMemoryPersistenceStrategy persistenceStrategy)
+  {
+    return new InMemoryChatroomFactory(persistenceStrategy);
+  }
+
+  @Bean
+  InMemoryPersistenceStrategy persistenceStrategy()
+  {
+    return new InMemoryPersistenceStrategy();
+  }
+
+  @Bean
+  public Clock clock()
+  {
+    return Clock.systemDefaultZone();
+  }
+}
index 4f33b11..b2b7f1d 100644 (file)
@@ -4,11 +4,9 @@ import de.juplo.kafka.chat.backend.domain.Chatroom;
 import de.juplo.kafka.chat.backend.domain.ChatroomFactory;
 import de.juplo.kafka.chat.backend.domain.PersistenceStrategy;
 import lombok.RequiredArgsConstructor;
-import org.springframework.stereotype.Component;
 
 import java.util.UUID;
 
-@Component
 @RequiredArgsConstructor
 public class InMemoryChatroomFactory implements ChatroomFactory
 {
index f6c76fa..454419e 100644 (file)
@@ -3,22 +3,15 @@ package de.juplo.kafka.chat.backend.persistence;
 import de.juplo.kafka.chat.backend.domain.Message;
 import de.juplo.kafka.chat.backend.domain.MessageMutationException;
 import de.juplo.kafka.chat.backend.domain.PersistenceStrategy;
-import lombok.Getter;
 import lombok.RequiredArgsConstructor;
-import lombok.Value;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
-import reactor.core.publisher.Sinks;
 
 import java.time.LocalDateTime;
 import java.util.LinkedHashMap;
-import java.util.UUID;
-import java.util.stream.Stream;
 
 
-@Component
 @RequiredArgsConstructor
 @Slf4j
 public class InMemoryPersistenceStrategy implements PersistenceStrategy