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

Question: How to get an instance of a class only from its token? #56

Open
rmtuckerphx opened this issue Sep 28, 2022 · 0 comments
Open

Comments

@rmtuckerphx
Copy link

I have code that runs in a pipeline and I want to use injection to provide an instance of 1 class for local dev, another for unit tests and the "real" one for production.

  1. Create the injector: jovo.$injector = createInjector();
  2. In code that only runs during dev, provide the class jovo.$injector.provideClass('myService', ServiceDev);
  3. ServiceDev class implements ServiceInterface. Other classes ServiceTest, ServiceProd.
  4. Get an instance of the class and assign to interface: const myService = jovo.$injector.injectClass('myService')
  5. Currently ServiceDev has no ctor params to inject. Other classes will.
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

No branches or pull requests

1 participant