Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Add isStrictDi to $injector #11728

Closed
kentcdodds opened this issue Apr 25, 2015 · 5 comments
Closed

Add isStrictDi to $injector #11728

kentcdodds opened this issue Apr 25, 2015 · 5 comments

Comments

@kentcdodds
Copy link
Member

I'm writing a utility library where I have a use case to know when strict DI is enabled on a given $injector. I could really use some reasonable way of knowing without having to do something crazy like:

function isStrictDi($injector) {
  try {
    $injector.invoke(function(a) {});
    return false;
  } catch(e) {
    return true;
  }
}

I'm thinking that we could just add a line that says instanceInjector.strictDi = strictDi right here before the instanceInjector is returned.

I would happily open a PR with tests which would do this. Just want to make sure this is the correct approach.

kentcdodds pushed a commit to kentcdodds/angular.js that referenced this issue Apr 27, 2015
Add a strictDi property which is true or false when creating an instance of an injector.

Closes angular#11728
@petebacondarwin
Copy link
Contributor

@kentcdodds what is the use case?

@petebacondarwin petebacondarwin added this to the 1.5.x - migration-facilitation milestone Apr 27, 2015
@kentcdodds
Copy link
Member Author

I'm building a tool to validate injectable functions. I would like to know if strictDi is turned on for the injector so I know whether to allow a simple function.

@kentcdodds
Copy link
Member Author

Here's the beginnings of the tool/lib: https://github.com/alianza-dev/angular-scope-types

@btford
Copy link
Contributor

btford commented Jun 15, 2015

Is this something that you'd ship with the production app, or just something you'd use while developing?

@kentcdodds
Copy link
Member Author

@btford, the library can be disabled (so it is a no-op for production). But it validates your DDO and I wanted to know whether your DDO should be using explicit annotation based on whether strict di is enabled (which I have enabled in development).

But thinking about it further, angular will throw an error if something's not using explicit annotation when it should be so I don't think it's valuable for me to validate that with this library. I'll go ahead and close this. Thanks!

lgalfaso pushed a commit that referenced this issue Sep 20, 2015
Add a strictDi property which is true or false when creating an instance of an injector.

Closes #11728
Closes #11734
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants