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
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
ExecutionContextis such a class.The
ExecutionContextis 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
ExecutionContextto Spring would simplify usage and code.Clients could just inject the current instance using Spring and the
ExecutionContextis not required to be passed down the object tree.By providing a dedicated scope like
recipe-scopeit 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:
scanwhich is then used to createExecutionContexts when a recipe starts.scanand the bean is recreated on each scan. The data with a shorter lifespan needs to be removed after each recipe executionRewriteMavenParser
The
RewriteMavenParserreads the.mvn/maven.configfrom project root. This makes this class ascan-scoped 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