Add a lazy composition root to application services#10
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR introduces an application-level composition root (ApplicationServices interface) backed by a Lazy memoization utility and LazyApplicationServices implementation with a fluent Builder for dependency injection. The context package is exported via module-info.java, and comprehensive tests validate lazy instantiation, caching, dependency isolation, and fail-fast validation. ChangesApplication Context Composition Root
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/pl/vtt/wpi/core/application/context/Lazy.java`:
- Around line 30-38: The branch in Lazy.get() that handles currentInitializer ==
null can never legitimately run and currently assigns a null to current,
violating the non-null contract; replace this dead guard with an explicit
failure (e.g., throw an AssertionError or IllegalStateException) to make the
invariant explicit and fail fast. Locate the synchronized block in class Lazy
(the method using variables initializer, value, current and Supplier<? extends
T>) and swap the "if (currentInitializer == null) { current = value; }" branch
for an assertion/exception indicating invariant violation (include a clear
message referencing initializer/value) so any unexpected state is loudly
reported instead of returning null.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 750444fd-1003-43d7-8e35-2115084f3896
📒 Files selected for processing (6)
docs/architecture-proposal.mdsrc/main/java/module-info.javasrc/main/java/pl/vtt/wpi/core/application/context/ApplicationServices.javasrc/main/java/pl/vtt/wpi/core/application/context/Lazy.javasrc/main/java/pl/vtt/wpi/core/application/context/LazyApplicationServices.javasrc/test/java/pl/vtt/wpi/core/application/context/LazyApplicationServicesTest.java
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RuntimeDataOutputPort.java (1)
25-27:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winRestore interrupt status on
InterruptedException— inconsistent with peerOutputPortadapters.Both
DeviceInfoOutputPortandUsersOutputPortin this same package check forInterruptedExceptionand callThread.currentThread().interrupt()before re-throwing.RuntimeDataOutputPortsilently clears the interrupt flag.🐛 Proposed fix
} catch (Exception e) { + if (e instanceof InterruptedException) { + Thread.currentThread().interrupt(); + } throw new OutputPortException("Cannot load runtime data", e); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RuntimeDataOutputPort.java` around lines 25 - 27, In RuntimeDataOutputPort's exception handling (the catch(Exception e) that throws new OutputPortException("Cannot load runtime data", e)), detect if the caught exception is an InterruptedException and if so call Thread.currentThread().interrupt() before rethrowing the OutputPortException; mirror the behavior in DeviceInfoOutputPort and UsersOutputPort so the thread's interrupt status is preserved when wrapping the exception into OutputPortException.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In
`@src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RuntimeDataOutputPort.java`:
- Around line 25-27: In RuntimeDataOutputPort's exception handling (the
catch(Exception e) that throws new OutputPortException("Cannot load runtime
data", e)), detect if the caught exception is an InterruptedException and if so
call Thread.currentThread().interrupt() before rethrowing the
OutputPortException; mirror the behavior in DeviceInfoOutputPort and
UsersOutputPort so the thread's interrupt status is preserved when wrapping the
exception into OutputPortException.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 879dcedb-0268-433d-893f-06e7fa031413
📒 Files selected for processing (40)
README.mddocs/architecture-proposal.mdsrc/main/java/module-info.javasrc/main/java/pl/vtt/wpi/core/application/context/ApplicationServices.javasrc/main/java/pl/vtt/wpi/core/application/context/Lazy.javasrc/main/java/pl/vtt/wpi/core/application/context/LazyApplicationServices.javasrc/main/java/pl/vtt/wpi/core/application/service/AdminPasswordService.javasrc/main/java/pl/vtt/wpi/core/application/service/UserManagementService.javasrc/main/java/pl/vtt/wpi/core/application/service/impl/AdminPasswordServiceImpl.javasrc/main/java/pl/vtt/wpi/core/application/service/impl/UserManagementServiceImpl.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/AuthOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/CurrentStateOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/DeviceInfoOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/LogsDeleteInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/PixelProgramsInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/PixelProgramsOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RestartInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RuntimeDataInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/RuntimeDataOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/UserCreateInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/UsersOutputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/WifiConfigInputPort.javasrc/main/java/pl/vtt/wpi/core/infrastructure/dto/AdminPasswordResetRequest.javasrc/main/java/pl/vtt/wpi/core/infrastructure/dto/PasswordDto.javasrc/main/java/pl/vtt/wpi/core/infrastructure/dto/UserCreateRequest.javasrc/test/java/pl/vtt/wpi/core/application/context/LazyApplicationServicesTest.javasrc/test/java/pl/vtt/wpi/core/application/service/impl/AdminPasswordServiceImplTest.javasrc/test/java/pl/vtt/wpi/core/application/service/impl/UserManagementServiceImplTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/AuthOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/CurrentStateOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/DeviceInfoOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/LogsDeleteInputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/PixelProgramsInputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/PixelProgramsOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/RestartInputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/RuntimeDataInputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/RuntimeDataOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/UserCreateInputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/UsersOutputPortTest.javasrc/test/java/pl/vtt/wpi/core/domain/port/WifiConfigInputPortTest.java
✅ Files skipped from review due to trivial changes (14)
- src/main/java/pl/vtt/wpi/core/application/service/AdminPasswordService.java
- src/test/java/pl/vtt/wpi/core/application/service/impl/AdminPasswordServiceImplTest.java
- src/test/java/pl/vtt/wpi/core/domain/port/DeviceInfoOutputPortTest.java
- src/main/java/pl/vtt/wpi/core/infrastructure/dto/UserCreateRequest.java
- src/test/java/pl/vtt/wpi/core/domain/port/UsersOutputPortTest.java
- src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/AuthOutputPort.java
- src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/CurrentStateOutputPort.java
- src/main/java/pl/vtt/wpi/core/application/service/impl/AdminPasswordServiceImpl.java
- src/test/java/pl/vtt/wpi/core/domain/port/RestartInputPortTest.java
- src/test/java/pl/vtt/wpi/core/domain/port/RuntimeDataOutputPortTest.java
- src/main/java/pl/vtt/wpi/core/infrastructure/adapter/http/PixelProgramsOutputPort.java
- src/test/java/pl/vtt/wpi/core/domain/port/AuthOutputPortTest.java
- src/test/java/pl/vtt/wpi/core/domain/port/CurrentStateOutputPortTest.java
- src/test/java/pl/vtt/wpi/core/application/context/LazyApplicationServicesTest.java
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/java/pl/vtt/wpi/core/application/context/ApplicationServices.java
- src/main/java/pl/vtt/wpi/core/application/context/LazyApplicationServices.java
- src/main/java/pl/vtt/wpi/core/application/context/Lazy.java
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/architecture-proposal.md`:
- Line 20: W zdaniu opisującym rolę LazyApplicationServices zamień kolokację
„pełni rolę composition root” na poprawną formę, np. „LazyApplicationServices
odgrywa rolę composition root” lub „LazyApplicationServices pełni funkcję
composition root”, aby użyć naturalnej polskiej frazeologii; zaktualizuj tylko
ten fragment w opisie odnoszącym się do LazyApplicationServices.
- Line 18: Zmień nagłówek sekcji który obecnie brzmi "Leniwa inicjalizacja i DI
przez konstruktor" na poprawną formę gramatyczną, np. "Leniwa inicjalizacja i DI
przez konstruktory" (alternatywnie "Leniwa inicjalizacja i DI konstruktorowe"),
aktualizując dokładnie tekst nagłówka "Leniwa inicjalizacja i DI przez
konstruktor" w dokumencie.
- Line 59: W zdaniu zawierającym porównanie dodaj brakujący przecinek: zmień
fragment "tak dobrze jak dedykowane gatewaye" na "tak dobrze, jak dedykowane
gatewaye" w miejscu opisującym generyczne InputPort<T> i OutputPort<T> oraz
przykłady UserGateway, RuntimeDataGateway i PixelProgramGateway.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bd3267dd-cf6c-49e6-8632-1562c1b02187
📒 Files selected for processing (1)
docs/architecture-proposal.md
Motivation
Description
pl.vtt.wpi.core.application.contextz interfejsemApplicationServicesbędącym fasadą dla przypadków użycia biblioteki. (src/main/java/pl/vtt/wpi/core/application/context/ApplicationServices.java).Lazy<T>i implementacjęLazyApplicationServicesz builderem, które rejestrują dostawców portów i tworzą konkretne serwisy dopiero przy pierwszym wywołaniu; zależności przekazywane są przez konstruktory istniejących implementacji usług. (src/main/java/pl/vtt/wpi/core/application/context/Lazy.java,.../LazyApplicationServices.java).module-info.java, aby eksportować pakietapplication.contexti udostępnić composition root klientom modułu. (src/main/java/module-info.java).src/test/java/pl/vtt/wpi/core/application/context/LazyApplicationServicesTest.java,docs/architecture-proposal.md).Testing
javac --release 25 -d /tmp/wpi-core-classes $(find src/main/java -name '*.java')i kompilacja zakończyła się pomyślnie.git diff --checknie zgłosiło problemów statycznych w zmianach (brak konfliktów/whitespace errors).mvn testzakończyła się niepowodzeniem z powodu niemożności pobraniamaven-resources-plugin:3.3.1(HTTP 403), amvn -o testrównież nie mogło uruchomić testów ponieważ wymagany plugin nie był dostępny w lokalnym cache.Codex Task
Summary by CodeRabbit
Refactor
Tests