intravenous
intravenous copied to clipboard
Use parameter names instead of $inject?
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?
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),
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.
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.
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!
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.
+1, getting started with Intravenous in Node.js and missing this.
@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
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...
Haha... Take whatever you want from our code of course if it helps.