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

Possibility of injection using interfaces #19

Closed
Anupamsdesk opened this issue Sep 18, 2017 · 1 comment
Closed

Possibility of injection using interfaces #19

Anupamsdesk opened this issue Sep 18, 2017 · 1 comment

Comments

@Anupamsdesk
Copy link

Anupamsdesk commented Sep 18, 2017

The following scenario is applicable for Typescript (only) I guess:

Is it possible to resolve dependencies when a class constructor is defined to have an interface instead of another class?

Consider the following scenario:
interface ITransport -> is defined and has get() method
Class Http -> implements ITransport interface
Class Service -> has a constructor with a paramerter of type ITransport

Is there a way we can use
ReflectiveInjector.resolveAndCreate([Service, Http])

Ideally if Http implements ITransport then shouldn't the dependency resolver be able to inject it automatically when creating an instance of Service class?

@mgechev
Copy link
Owner

mgechev commented Sep 18, 2017

No, declaration of providers as interfaces is not possible because typescript strips them compile time.

@mgechev mgechev closed this as completed Sep 18, 2017
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

2 participants