Add a lazy composition root to application services#10
Conversation
|
ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis pull request introduces a dependency injection composition root using lazy initialization and constructor-based wiring. It establishes Clean Architecture alignment by separating domain ports from HTTP-specific infrastructure, exports a new ChangesClean Architecture Composition Root
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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 docstrings
🧪 Generate unit tests (beta)
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
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
New Features
Chores
Documentation
Tests