Skip to content

feat(core): unify service binding precedence - #98

Merged
medz merged 1 commit into
mainfrom
feat/service-binding-precedence
Oct 25, 2026
Merged

medz merged 1 commit into
mainfrom
feat/service-binding-precedence

Conversation

@medz

@medz medz commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Use declaration-order replacement consistently across Context construction, Context merging, Layer outputs, and local provision. Later bindings win, inputs remain immutable, and Context.add inserts or replaces a single binding:

final port = ServiceKey<int>('port');
final production = Context.from([port.bind(443)]);
final testing = production.add(port.bind(8080));
assert(production.merge(testing).read(port) == 8080);
assert(production.read(port) == 443);

Remove Context.replace, DuplicateService, and the separate internal overlay operation. Layer completion order does not change output precedence; replaced resources keep their owning lifetime, and existing dependants are not rebuilt.

Related issues

Closes #15

Validation

  • dart pub get
  • dart format --output=none --set-exit-if-changed .
  • dart analyze --fatal-infos
  • dart test — 1,349 tests passed
  • Covered immutable insertion/replacement, null bindings, nested provision, out-of-order Layer construction, failure propagation, and replaced-resource cleanup.

Summary by CodeRabbit

  • New Features
    • Added Context.add to insert a service binding or update an existing one, including with a null value.
  • Changes
    • When service keys repeat in a context or merged layers, the later binding now takes precedence.
    • Removed Context.replace and the DuplicateService exception.
    • Layer merging continues to build all branches; later-declared layers determine the binding even if they finish later.
  • Documentation
    • Clarified provider precedence, dependency behavior, resource lifetimes, and concurrency limits.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T11:03:56.183840Z c4ff537 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@medz medz added the enhancement New feature or request label Oct 25, 2026 — with ChatGPT Codex Connector

medz commented Oct 25, 2026

Copy link
Copy Markdown
Member Author

@codex review

@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

Context construction, merging, and single-binding updates now use last-binding-wins semantics. Runtime and provider composition use the same merge operation. Layer documentation and tests cover output precedence, nested provisioning, retained dependants, and resource cleanup. DuplicateService and Context.replace are removed.

Changes: Service replacement behavior

Layer / File(s) Summary
Context replacement contract
lib/src/core/context.dart, lib/any.dart, test/core/context_test.dart
Context.from and Context.merge keep the later binding. Context.add inserts or replaces a binding. The DuplicateService exception and Context.replace method are removed. Tests cover replacement, null bindings, and immutable inputs.
Runtime and provider context composition
lib/src/core/runtime.dart, lib/src/core/task.dart, test/core/task_context_test.dart, test/core/layer_test.dart
Runtime and provider context composition use Context.merge. Tests cover nested provider precedence, inherited bindings, and unchanged caller context.
Layer output precedence and resource lifetime
lib/src/core/layer.dart, test/core/layer_concurrency_test.dart, test/core/layer_test.dart
Layer documentation describes output precedence, dependency capture, and resource ownership. Tests cover out-of-order builds, failed builds, replaced outputs, and resource release.

Priority: Not assessed

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Possibly related issues

Suggested labels: enhancement

Merge Risk: Minimal · up to c4ff5

No issue requiring a change before merge was established; proceed with normal checks.

Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: c4ff5372d2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@medz
medz merged commit 0e678ca into main Oct 25, 2026
2 of 3 checks passed
@medz
medz deleted the feat/service-binding-precedence branch October 25, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unify service combination rules across Context and Layer

1 participant