You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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, ...)
publicMyAction {
// The context from current 'recipe-scope' will be injected@AutowiredprivateExecutionContextctx;
}
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:
The ExecutionContext is created on each recipe execution and the data normally set during scan (in OR) is kept and passed to the ExecutionContext when the first recipe gets executed. This could be done by keeping this data in a bean scoped to scan which is then used to create ExecutionContexts when a recipe starts.
The ExecutionContext has itself a scope of scan and the bean is recreated on each scan. The data with a shorter lifespan needs to be removed after each recipe execution
RewriteMavenParser
The RewriteMavenParser reads the .mvn/maven.config from project root. This makes this class a scan-scoped bean.
It has to be recreated on each new scan of a project. It also requires access to the ExecutionContext.
What needs to be done
Introduce custom bean scope recipe-scope and verify in test
The text was updated successfully, but these errors were encountered:
Discussed in #785
Originally posted by fabapp2 May 9, 2023
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
.What needs to be done
recipe-scope
and verify in testThe text was updated successfully, but these errors were encountered: