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

How to check whether dependency exists #7

Open
ernsheong opened this issue May 9, 2019 · 2 comments
Open

How to check whether dependency exists #7

ernsheong opened this issue May 9, 2019 · 2 comments

Comments

@ernsheong
Copy link

ernsheong commented May 9, 2019

di.get("i-dont-exist")

throws an error. Is there a gentler way to check whether a dependency exists?

My use case is that I added a dependency dynamically. A consumer of the dependency wants to check whether it is present before continuing.

@ernsheong
Copy link
Author

Ah I found it:

di.exists = container.exists.bind(container)

One for the docs perhaps? We should document entire container API here: https://github.com/di-ninja/di-ninja#5-container

@devthejo
Copy link
Member

devthejo commented May 9, 2019

Yes you're right, I have not the time to do that for now, but feel free to make a pull request for this, I'll accept it.

PS: di-ninja remain maintained and a good choice in many situation but with the new stable react context api for the browser and the experimental feature async_hook in node, I can do most of my dependency injection works natively.

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