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

basic support for Dependency Injection #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jose-carmona
Copy link

Support for Dependency Injection based on Injector.

Example

Provider:

class AppModule(Module):
    @provider
    @singleton
    def provide_str(self) -> str:
        return 'TEST INJECTED'

    @provider
    @singleton
    def provide_int(self) -> int:
        return 42

Init:

app = Flask(__name__)
module = AppModule()
injector = Injector([module])
assist = Assistant(app, project_id="test-project-id", injector=injector)

Dependency Injection in action decorator:

@assist.context("context_1")
@assist.action("intent_with_context_injects_params")
@inject
def intent_with_context_injects_params(speech: str, p1, p2, i: int):
    return ask("context_1:" +speech + ":" + p1 + ":" + p2 + ":" +str(i))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant