Closed bsideup closed 9 years ago
It is impossible to inject the workflow because it's instantiation is outside of our control. It is constructed by the Flow framework. I agree that is a little frustrating, but you probably don't need to inject the workflow anyway. The workflow should just coordinate activities, and it is trivial to do DI (with whatever framework you want) on your activities because you do control their instantiation.
Our workflow is complicated and spawn activities based on current database state. Since activities are flow-less we can't move this logic to them.
Btw, I found a way to use Glisten with Spring:
@Bean(destroyMethod = "shutdownNow")
public GenericWorkflowWorker genericWorkflowWorker(AmazonSimpleWorkflow amazonSimpleWorkflow, ApplicationContext applicationContext) throws IllegalAccessException, InstantiationException {
GenericWorkflowWorker workflowWorker = new GenericWorkflowWorker(amazonSimpleWorkflow, domain, taskList);
POJOWorkflowDefinitionFactoryFactory workflowDefinitionFactoryFactory = new POJOWorkflowDefinitionFactoryFactory() {
@Override
protected POJOWorkflowImplementationFactory getImplementationFactory(Class<?> workflowImplementationType, Class<?> workflowInterface, WorkflowType workflowType) {
return new POJOWorkflowImplementationFactory() {
@Override
public Object newInstance(DecisionContext decisionContext) throws Exception {
return applicationContext.getBean(workflowInterface);
}
@Override
public void deleteInstance(Object instance) {
}
};
}
};
workflowDefinitionFactoryFactory.addWorkflowImplementationType(ClubWarProcessorWorkflowImpl.class);
workflowWorker.setWorkflowDefinitionFactoryFactory(workflowDefinitionFactoryFactory);
return workflowWorker;
}
Wow, I didn't know that was possible. Nice!
Now I have Spring Java-only project with Glisten-based SWF workflow where only *WorkflowImpl file is in Groovy, everything else in pure Java. I can contribute an example of usage because I think this is a good case for Glisten and especially for projects where main language is Java:)
@bsideup I would love to see that example if you can make it available.
There is the Flow Spring package as well that includes SpringWorkflowWorker, which I think does something similar. They also recommend setting the Workflow to a special scope they define.
Hi!
Can I get some docs how to integrate Glisten with Spring? For example, how to autowire some dependencies in workflow
Thanks!