spring-cloud / spring-cloud/spring-cloud-config

[Refactoring] Introduce RequestContext to easily pass new parameters to downstream methods

Open
#2,407 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

Is your feature request related to a problem? Please describe.
In the current implementation, it's necessary to change a bunch of method signatures when we introduce new HTTP parameters and pass them to downstream methods.

Let's say you introduce the new parameter forceRefresh like #2402.
In this case, you need to change the signature of EnvironmentRepository and SearchPathLocator and modify a lot of classes that implement those interfaces.

Before introducing forceRefresh

public interface EnvironmentRepository {
	Environment findOne(String application, String profile, String label);
        Environment findOne(String application, String profile, String label, boolean includeOrigin);
}

public interface SearchPathLocator {
	Locations getLocations(String application, String profile, String label);
}

After introducing forceRefresh

public interface EnvironmentRepository {
	Environment findOne(String application, String profile, String label);
        Environment findOne(String application, String profile, String label, boolean includeOrigin);
        Environment findOne(String application, String profile, String label, boolean includeOrigin, boolean forceRefresh);
}

public interface SearchPathLocator {
	Locations getLocations(String application, String profile, String label);
        Locations getLocations(String application, String profile, String label, boolean forceRefresh);
}

Describe the solution you'd like
Introduce RequestContext and change the interface of EnvironmentRepository and SearchPathLocator like below.

public interface EnvironmentRepository {
	Environment findOne(RequestContext ctx);
}

public interface SearchPathLocator {
	Locations getLocations(RequestContext ctx);
}

When you introduce new HTTP parameters, you can just change RequestContext and don't need to change a bunch of method signatures like the current implementation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the EnvironmentRepository and SearchPathLocator interfaces and tracing their implementers and callers. Review how HTTP parameters currently reach downstream methods, then assess the RequestContext migration. Done means both interfaces accept RequestContext and adding a parameter no longer requires changing many downstream method signatures.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring, spring-boot
Domain
api, backend, backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.