Skip to content

Improve documentation clarity in di-kodein-advanced sample#333

Open
Kingjha13 wants to merge 2 commits intoktorio:mainfrom
Kingjha13:improve-di-kodein-documentation
Open

Improve documentation clarity in di-kodein-advanced sample#333
Kingjha13 wants to merge 2 commits intoktorio:mainfrom
Kingjha13:improve-di-kodein-documentation

Conversation

@Kingjha13
Copy link

This PR improves inline documentation and README clarity in the
di-kodein-advanced sample.

No functional changes were introduced.

The goal is to make the sample easier to understand for new users
exploring dependency injection with Kodein in Ktor.

@coderabbitai
Copy link

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55bf7d7 and beaa4e6.

📒 Files selected for processing (1)
  • di-kodein-advanced/README.md

Walkthrough

Reworks the di-kodein-advanced sample: README updated to emphasize Kodein DI with Ktor; application bootstrap refactored to use a DI-based advancedApplication() hook that binds repository and controller, and routes/controllers are auto-discovered and resolved from the DI container.

Changes

Cohort / File(s) Summary
Documentation
di-kodein-advanced/README.md
Title changed to "Kodein-DI (Advanced)". Rewrote description, replaced "Running" with "This example shows:", added "Running the Sample" instructions (./gradlew run), browser navigation examples (http://localhost:8080/users, http://localhost:8080/users/{name}), project structure overview, and minor formatting edits.
Application Bootstrapping & Routing
di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt
Replaced manual bootstrap with kodeinApplication usage. Added DI.MainBuilder.advancedApplication(application) to bind DefaultHeaders, Users.Repository, and Users.Controller into DI. Routing updated to auto-discover/resolve controllers from DI and use resource-typed route handlers; removed debug prints and adjusted HTML generation/parameter naming.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • e5l
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: improving documentation clarity in the di-kodein-advanced sample, which aligns with the README restructuring and expanded instructions in the changeset.
Description check ✅ Passed The description is related to the changeset, mentioning documentation and README clarity improvements for the di-kodein-advanced sample, which matches the actual changes made.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt (2)

24-29: ⚠️ Potential issue | 🟠 Major

This is a functional change, not documentation-only.

The PR objective states “no functional changes,” but this introduces new application bootstrap and dynamic route registration behavior. Please either split docs vs behavior into separate PRs or update the PR scope and add regression coverage for startup/route registration.

Also applies to: 125-158

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt`
around lines 24 - 29, The change replaces the previous static bootstrap with a
new runtime bootstrap (main -> embeddedServer(Netty, port = 8080) {
kodeinApplication { application -> advancedApplication(application) } }) which
alters application startup and dynamic route registration behavior (see main,
kodeinApplication, advancedApplication); either revert this functional change
back to the original non-runtime behavior or split the change into two PRs (one
for docs and one for behavior) and add regression tests that cover application
startup and route registration (integration tests that start the server and
assert routes registered by advancedApplication are present) to validate the new
behavior before merging.

143-152: ⚠️ Potential issue | 🟠 Major

Use multi-binding (Set) pattern instead of container introspection for controller discovery.

The current findControllers() implementation uses kodein.container.tree.bindings.keys with type-only resolution (kodein.Instance(bind.type)), which breaks with tagged or contextual controller bindings. The container introspection API is documented as "advanced knowledge" (debugging-oriented) rather than a stable discovery mechanism. Instead, bind controllers as a Set<KodeinController> during DI configuration and inject the complete set at startup—this properly handles tagged, contextual, and factory bindings.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt`
around lines 143 - 152, The findControllers function is using container
introspection (kodein.container.tree.bindings.keys and
kodein.Instance(bind.type)) which fails for tagged/contextual bindings; replace
this discovery by registering controllers into a multi-binding Set at DI
configuration (use bindSet/add or the Kodein multi-bind API to bind each
controller into a Set<KodeinController>) and then inject that
Set<KodeinController> at startup instead of calling findControllers; remove or
stop using kodein.container.tree and kodein.Instance(bind.type) in
findControllers and instead obtain the controllers via the DI-provided
Set<KodeinController> (e.g., the injected set from the DI container).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@di-kodein-advanced/README.md`:
- Around line 25-35: The fenced code blocks showing the example URLs (the blocks
containing "http://localhost:8080/users" and
"http://localhost:8080/users/{name}") need language identifiers to satisfy
markdownlint MD040; update each triple-backtick fence to use the text language
(i.e., replace ``` with ```text for both URL blocks) so the README markdown
lints cleanly.

---

Outside diff comments:
In
`@di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt`:
- Around line 24-29: The change replaces the previous static bootstrap with a
new runtime bootstrap (main -> embeddedServer(Netty, port = 8080) {
kodeinApplication { application -> advancedApplication(application) } }) which
alters application startup and dynamic route registration behavior (see main,
kodeinApplication, advancedApplication); either revert this functional change
back to the original non-runtime behavior or split the change into two PRs (one
for docs and one for behavior) and add regression tests that cover application
startup and route registration (integration tests that start the server and
assert routes registered by advancedApplication are present) to validate the new
behavior before merging.
- Around line 143-152: The findControllers function is using container
introspection (kodein.container.tree.bindings.keys and
kodein.Instance(bind.type)) which fails for tagged/contextual bindings; replace
this discovery by registering controllers into a multi-binding Set at DI
configuration (use bindSet/add or the Kodein multi-bind API to bind each
controller into a Set<KodeinController>) and then inject that
Set<KodeinController> at startup instead of calling findControllers; remove or
stop using kodein.container.tree and kodein.Instance(bind.type) in
findControllers and instead obtain the controllers via the DI-provided
Set<KodeinController> (e.g., the injected set from the DI container).

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ca0054 and 55bf7d7.

📒 Files selected for processing (2)
  • di-kodein-advanced/README.md
  • di-kodein-advanced/src/main/kotlin/io/ktor/samples/kodein/KodeinAdvancedApplication.kt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant