Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Support for dependency injection (pinject) #295

Closed
grizzlybearer opened this issue Mar 10, 2023 · 1 comment
Closed

[Feature Request] Support for dependency injection (pinject) #295

grizzlybearer opened this issue Mar 10, 2023 · 1 comment
Labels
question Further information is requested

Comments

@grizzlybearer
Copy link

In order to use Temporal in our systems, we need the ability to inject dependencies such as grpc connections, db connections, kafka connections, auth data into temporal workflows and activities, using pinject, that are scoped at different levels (global, customer specific).

Here's an example:
Say you have a python class to fetch customer scoped data from redis:

from pinject import new_object_graph
import redis

class CustomerDataAccess:
    def __init__(self, customer_partition):
       # this is simplified. IRL there would be nested dependencies injected
        self.customer_partition = customer_partition
        self.redis_client = redis.Redis()

    def get_data(self):
        # Access data from the specified customer partition in Redis
        data = self.redis_client.get(self.customer_partition)
        return data

and then you have a workflow and an activity that needs this dependency:

# Define the Workflow interface
class CustomerWorkflow:
    @workflow_method(task_queue="customer-data")
    def get_customer_data(self) -> str:
        pass

# Implement the Workflow
class CustomerWorkflowImpl(CustomerWorkflow):
    def __init__(self, customer_data_access: CustomerDataAccess):
        self.data_access = customer_data_access

    def get_customer_data(self) -> str:
        # Access data from a specific customer partition using the Activity
        data = self.data_access.get_data("customer1")
        # do business logic on this data
        return result

Describe the solution you'd like

Proposed solution: Add support for pinject, similar to how you folks added support for Spring Boot in Java: temporalio/sdk-java#745

Additional context

@grizzlybearer grizzlybearer added the enhancement New feature or request label Mar 10, 2023
@cretz cretz added question Further information is requested and removed enhancement New feature or request labels Mar 10, 2023
@cretz
Copy link
Member

cretz commented Mar 10, 2023

Closing as question/duplicate. Duplicate post at https://community.temporal.io/t/python-support-for-dependency-injection-pinject/7538 is a better place to discuss.

@cretz cretz closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants