Injected WorkflowContext vs ThreadLocal

Hi,
I was wondering about the design decision to go with a thread-local based Workflow in the Java SDK. Since the lifecycle of the workflow handler instance is controlled by temporal, wouldn’t this design be more natural to Java developers:

@WorkflowInterface
public class MyWorkflow {
    @Context
    Logger logger;

    @Context
    Workflow ctx;

    @WorkflowMethod
    public void main() {
       // not using static method anymore
        ctx.sleep(100);
    }
}

The @Context annotation would be reusable in actions and can do the proper thing based on the field type - for example replace ThreadLocals with WorkflowThreadLocal, populate loggers with Workflow.getLogger(), etc.

I am assuming that a workload class instance will be serving just one execution - unlike a servlet. I’m new to Temporal so probably I’m missing something :slight_smile:

The core design that uses thread locals allows to implement workflows without relying on a IoC container.

I agree that a lot of Java developers are using one of such containers and are used to dependency injection. We do plan provide integrations with such containers in the future and the code similar to your sample will be possible.

I believe Spring Boot is the most requested integration.