Skip to content

Adding AdapterFinderBean and interceptor functionality. #34744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joe-chambers
Copy link

AdapterFinderBean and AdapterFinderInterceptor allow for similar functionality to ServiceLocatorFactoryBean but without the call from the client to find the appropriate service bean for each call. This crosscutting concern can be implemented in an "AdapterFinderBean" used by an "AdapterFinderInterceptor" proxy bean that directs the method call to the "Adapter" returned by the "AdapterFinderBean"

Problem:

A business logic process such as "shipping" requires access to multiple services i.e. UPS, USPS, DHL, and FEDEX existing solutions at best require cluttering the client space with calls to find the service and then call it. When expanding from a single shipping service to an array of adapters this requires significant changes throughout the coad base with client pollution.

Solution:

In order to reduce the client side polution and make a flexible system, an AdapterFinderBean can be implemented so that it has access to each implementation by "Qualifier" and based on one or more of the method parameters (TenantId, CustomerId, OrderId, etc...) the finder determines which implementation of the defined Adapter interface to return.

Example

Each implementation has an Adapter implementation of a defined interface e.g. UPSShippingAdapter, USPSShippingAdapter, DHLShippingAdapter, and FEDEXShippingAdapter all implementations of the ShippingAdapter interface.

A "Finder" ShippingAdapterFinder implements the AdapterFinderBean with qualifier based access to all of the ShippingAdapter implementations. The finder returns the appropriate implementation based on the parameters passed in to each call such as TenantId, CustomerId, OrderId, and etc....

The AdapterFinderInterceptor is used to construct a "Proxy" of the ShippingAdapter that will query the "ShippingAdapterFinder" to determine which concrete implementation to pass the method call on to.

Additionally this same structures could be used to lookup based on feature flags, or properties (potentially a beta vs legacy) or versions i.e. a telephone system where the east coast (US) has upgraded from version 14 of the SIP server to version 16, but central, and west coast (US) have not.

Further

It is thought that a spring-cloud or spring-boot implementation could look through the bean definition registry to find implementations of the AdapterFinderBean, and create a "Primary" instance of the interface the AdapterFinderBean returns that is proxy bean that uses the finder in the application context.

Please excuse the terminology, you probably have better terminology this is my first PR into the spring ecosystem.

AdapterFinderBean and AdapterFinderInterceptor allow for similar
functionality to ServiceLocatorFactoryBean but without the call from
the client to find the appropriate service bean for each call.

It would be anticipated that spring-boot functionality would be
created in the future to search the bean definition registry after
the registry is created to find finder beans and build proxies for
the interfaces exposed by them and register those implementations
within the application context.

Signed-off-by: Joe Chambers <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants