From 28200ecd7c389516e062dc21733ef184f7985fda Mon Sep 17 00:00:00 2001 From: i3ats Date: Mon, 26 Aug 2024 16:07:12 -0400 Subject: [PATCH] Use Lombok and Guice to remove some boilerplate --- .../java/com/joevno/exampleproject/SomeServiceImpl.java | 9 +++------ src/main/java/com/joevno/exampleproject/MyService.java | 7 ++----- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/modules/some-impl/src/main/java/com/joevno/exampleproject/SomeServiceImpl.java b/modules/some-impl/src/main/java/com/joevno/exampleproject/SomeServiceImpl.java index b1c51b0..3c34f2f 100644 --- a/modules/some-impl/src/main/java/com/joevno/exampleproject/SomeServiceImpl.java +++ b/modules/some-impl/src/main/java/com/joevno/exampleproject/SomeServiceImpl.java @@ -2,23 +2,20 @@ import com.google.auto.service.AutoService; import jakarta.inject.Inject; +import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * Concrete implementation of the SomeService interface. */ +@RequiredArgsConstructor(onConstructor = @__(@Inject)) public class SomeServiceImpl implements SomeService { private static final Logger LOGGER = LogManager.getLogger(); private final AnotherService anotherService; - - @Inject - SomeServiceImpl(AnotherService anotherService) { - this.anotherService = anotherService; - } - + @Override public void performService() { LOGGER.info("Performing Service"); diff --git a/src/main/java/com/joevno/exampleproject/MyService.java b/src/main/java/com/joevno/exampleproject/MyService.java index 2bf2690..fff2d67 100644 --- a/src/main/java/com/joevno/exampleproject/MyService.java +++ b/src/main/java/com/joevno/exampleproject/MyService.java @@ -1,21 +1,18 @@ package com.joevno.exampleproject; import jakarta.inject.Inject; +import lombok.RequiredArgsConstructor; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * This class is a simple service that logs a message. */ +@RequiredArgsConstructor(onConstructor = @__(@Inject)) class MyService { private static final Logger LOGGER = LogManager.getLogger(); private final SomeService someService; - @Inject - MyService(SomeService someService) { - this.someService = someService; - } - void performService() { LOGGER.info("Performing Service"); someService.performService();