Conversation
Introduce a declarative port/adapter mechanism for wiring infrastructure
dependencies into feature slices, replacing the preConfigure callback.
API (sliceworkz-eventmodeling-api):
- Add adapter(Object)/port(Class)/port(Class, String) to BoundedContextBuilder
- Add AdapterBinding and QualifiableAdapterBinding for fluent chaining
with optional .withQualification("name") for named bindings
- Remove preConfigure from FeaturesSpecification
Implementation (sliceworkz-eventmodeling-impl):
- Add AdapterRegistry with register/lookup/requalify operations
- Assignability check: adapter must implement the port type
- Fail-fast: missing port lookup throws IllegalStateException at build time
- Duplicate detection: registering same port+qualification twice throws
- DelegatingBoundedContextBuilder enables QualifiableAdapterBinding to
continue the builder chain fluently
Benchmark refactoring:
- OrderProcessingFeatureSlice is now a clean marker interface (no preConfigure)
- Feature slices use builder.port(DataSource.class) and
builder.port(DatabaseInitMode.class) in their configure methods
- BenchmarkApplication uses .adapter(ds).forPort(DataSource.class) and
.adapter(initMode).forPort(DatabaseInitMode.class)
- Eliminated mutable fields and two-phase initialization from all slices
https://claude.ai/code/session_01L4BtP5BGKBqwTe3rYphCK1
…ectly Remove QualifiableAdapterBinding and DelegatingBoundedContextBuilder. Follow the same pattern as FeaturesSpecification.done() and LiveModelSpecification.live() where the terminal method returns the builder directly. AdapterBinding.forPort(Class) now returns BoundedContextBuilder, and an overload forPort(Class, String) handles qualified bindings. This also removes the requalify() method from AdapterRegistry since qualification is now provided upfront. https://claude.ai/code/session_01L4BtP5BGKBqwTe3rYphCK1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new adapter registry pattern to the bounded context builder, enabling flexible dependency injection and port binding. This replaces the previous pre-configuration callback approach with a more declarative and type-safe mechanism.
Key Changes
New
AdapterRegistryclass: A registry that stores adapter-to-port bindings with optional qualifications, supporting both default and named qualifications for the same port type.New
AdapterBindinginterface: An intermediate builder step that allows fluent binding of adapters to ports viaadapter(instance).forPort(PortType)syntax.Extended
BoundedContextBuilderAPI:adapter(Object)- starts an adapter bindingport(Class<T>)- retrieves an adapter for a port type with default qualificationport(Class<T>, String)- retrieves an adapter for a port type with named qualificationRemoved
preConfigurecallback: Eliminated theFeaturesSpecification.preConfigure()method and its implementation, replacing it with the adapter registry pattern for cleaner separation of concerns.Updated feature slices: Modified benchmark feature slices to use the new adapter pattern instead of pre-configuration callbacks. Adapters are now retrieved directly from the builder during configuration rather than being set up beforehand.
Implementation Details
AdapterRegistryuses aPortKeyrecord to uniquely identify adapter bindings by port type and qualification string.BoundedContextBuilderImplas an inner classAdapterBindingImplthat delegates to the registry.DataSourceandDatabaseInitMode) through the builder'sport()methods rather than through pre-configuration.This change provides a more declarative, type-safe, and testable approach to managing cross-cutting dependencies in bounded contexts.
https://claude.ai/code/session_01L4BtP5BGKBqwTe3rYphCK1