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))
        }
    }
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      SpringContextProvider(ApplicationContext applicationContext)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      <T extends Any> T getFromContext(Class<T> type) Retrieve an object of the specified type from the context.
      Boolean hasInContext(Class<?> type) Check if an object of the specified type is available in the context.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SpringContextProvider

        SpringContextProvider(ApplicationContext applicationContext)
        Parameters:
        applicationContext - the Spring application context to retrieve beans from
    • 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