Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Use parameter names instead of $inject? #1

Open
seanhess opened this issue Jun 25, 2012 · 9 comments
Open

Use parameter names instead of $inject? #1

seanhess opened this issue Jun 25, 2012 · 9 comments

Comments

@seanhess
Copy link

I'm curious whether you think it is a bad idea to inject based on function parameter names instead of using func.$inject.

Specifically, are there any pitfalls you can see for server side node.js code that doesn't need to be minified? Is this something you will add to the library?

@sagacity
Copy link
Owner

You are right, the main reason is to avoid problems during minification or bundling. The reason it's not implemented is because I simply did not yet have the need for it.

One thing that would have to be decided is what to do with the abbreviation for the nullable facility (since ? is not a valid part of the name),

@seanhess
Copy link
Author

Gotcha. No worries. I already wrote a function that wraps the function and sets $inject based on the parameter names. I think it should be optional.

In coffee-script the following would be equivalent:

# before
MyClass = (something) ->
MyClass.$inject = ["something"]

# after
MyClass = autoInject (something) ->

So you could start with autoInject for lots of things, but if you needed to use an optional dependency you could use the $inject syntax.

@sagacity
Copy link
Owner

Yes, that sounds like a reasonable solution. I'd want to specify the container though, so probably another method on the container object itself would be a good way to do it.

So instead of get you'd call autoGet or something.

@seanhess
Copy link
Author

I'm ok with anything, or nothing: I can write something myself.

I'm not sure I understand your last comment. The func.$inject property is independent of the container, right? All I'd like is some way to automatically set the $inject property to match the parameter list of the function. It doesn't seem to have anything to do with the container.

But I can write something myself if you don't feel like adding it to the library. So either way. Thanks!

@sagacity
Copy link
Owner

Oh, so the autoInject just creates the $inject property instead of actually resolving the object? That's even simpler, yes. Maybe that would be a good candidate for inclusion in the core library.

@domenic
Copy link

domenic commented Aug 30, 2012

+1, getting started with Intravenous in Node.js and missing this.

@seanhess
Copy link
Author

@domenic Sorry to hijack intravenous' thunder, because it's an awesome framework, but we ended up rolling our own. https://github.com/idottv/dependable - it's not as powerful as intravenous, but it injects based on the name

@sagacity
Copy link
Owner

sagacity commented Oct 4, 2012

Thunder stolen! :)
Seriously though, it's worth including. I finally have some more time to work on it, so hopefully I can add it asap.

Now, if only I can find out how to restrict @seanhess 's IP range from using it...

@seanhess
Copy link
Author

seanhess commented Oct 4, 2012

Haha... Take whatever you want from our code of course if it helps.

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

No branches or pull requests

3 participants