Class SpringContextProvider
-
- All Implemented Interfaces:
-
com.embabel.agent.api.annotation.support.ContextProvider
@Component() public final class SpringContextProvider implements ContextProvider
Spring implementation of ContextProvider that retrieves objects from the Spring ApplicationContext.
This enables injection of Spring beans into action methods using the com.embabel.agent.api.annotation.Provided annotation.
Example:
@State data class MyState(val data: String) { @Action fun process(@Provided myService: MyService): NextState { return NextState(myService.transform(data)) } }
-
-
Constructor Summary
Constructors Constructor Description SpringContextProvider(ApplicationContext applicationContext)
-
Method Summary
Modifier and Type Method Description <T extends Any> TgetFromContext(Class<T> type)Retrieve an object of the specified type from the context. BooleanhasInContext(Class<?> type)Check if an object of the specified type is available in the context. -
-
Method Detail
-
getFromContext
<T extends Any> T getFromContext(Class<T> type)
Retrieve an object of the specified type from the context.
- Parameters:
type- the class of the object to retrieve- Returns:
the object instance, or null if not available
-
hasInContext
Boolean hasInContext(Class<?> type)
Check if an object of the specified type is available in the context.
- Parameters:
type- the class to check for- Returns:
true if an object of this type can be provided
-
-
-
-