Replies: 2 comments
-
The
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Another attempt...
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Scoped Spring Beans
Some objects must exist only once per application, these are a perfect fit for singleton-scoped beans.
But, some other beans have a lifetime shorter than the application itself.
Additionally, these should exist once per thread that executes (theoretically, because static instances currently prevent parallel threads).
ExecutionContext
OpenRewrite's
ExecutionContext
is such a class.The
ExecutionContext
is populated with data available on every new scan, e.g. Maven configuration information.Additionally, it contains data with a potentially shorter lifespan (of a recipe execution), e.g. error information or messages.
Moving the creation and destruction (or clean up) of the
ExecutionContext
to Spring would simplify usage and code.Clients could just inject the current instance using Spring and the
ExecutionContext
is not required to be passed down the object tree.By providing a dedicated scope like
recipe-scope
it would be possible to inject the "right" instance (scoped to current thread and recipe execution) to all objects that share the same or narrower lifespan (Recipe, Action(s), Conditions, ...)OpenRewrite populates data to the ExecutionContext as early as during the scan of an application.
From SBM's perspective, the ExecutionContext contains data with different scopes: scan and recipe-execution.
This means either:
scan
which is then used to createExecutionContext
s when a recipe starts.scan
and the bean is recreated on each scan. The data with a shorter lifespan needs to be removed after each recipe executionRewriteMavenParser
The
RewriteMavenParser
reads the.mvn/maven.config
from project root. This makes this class ascan-scope
d bean.It has to be recreated on each new scan of a project. It also requires access to the
ExecutionContext
.Beta Was this translation helpful? Give feedback.
All reactions