Closed Sharaal closed 8 years ago
@dragonprojects I'm intrigued by the aliases idea. That is originally why I made the inject
method available. It was to handle modules with invalid variable names.
Out of curiosity, what is your issue with the inject
method?
Oh, i deleted my comment... So new try. :)
I think the inject method brakes the concept behind the injector.
The key concept is to give the module all the dependencies per function parameter. With the inject method the module must take the dependencies itself.
Another reason is more complexity in unit testing. Instead of giving the module the mock object for the dependency I must mock the inject method to return the mock objects depends on the name.
Both strange behavior only cause of special characters in the name. I think thats not a clear concept and behavior. The aliases remove with stranges and make it clear.
That is a very valid argument. And I agree with you. Is this PR a fix for that?
As far as unit testing, the inject method automatically works the same as injected dependencies (right now).
On Tue, Aug 19, 2014 at 12:53 PM, Christoph Herrmann notifications@github.com wrote:
Oh, i deleted my comment... So new try. :) I think the inject method brakes the concept behind the injector. The key concept is to give the module all the dependencies per function parameter. With the inject method the module must take the dependencies itself. Another reason is more complexity in unit testing. Instead of giving the module the mock object for the dependency I must mock the inject method to return the mock objects depends on the name.
Both strange behavior only cause of special characters in the name. I think thats not a clear concept and behavior. The aliases remove with stranges and make it clear.
Reply to this email directly or view it on GitHub: https://github.com/scottcorgan/Injector/pull/36#issuecomment-52689130
Yes, the pull request add the aliase feature to the injector to support dependencies with special characters in that clear way for the module.
After nearly two years, the still open pull-request can closed.
Hi,
my first pull request, but I hope it will works to send you a little improvement to your greate project. :)
Introduction
The injector allows to load modules from "node_modules" per inject and per defining as dependency. So:
Is the same as:
And the same as:
Problem
But the problem are modules with special characters in the name, like "body-parser" (connector extension for express).
So this will not work, its a syntax error:
Solution
Cause of this problem I add the possibility to define aliases for the Injector.
So with this feature you can add aliases to the injector configuration:
And now use the alias as dependency for modules:
Implementation
I add the aliases to the register method and replace the names in the dependency configuration of the modules. This was the only central location I found to check and replace the aliases for both types of modules (parsed modules and modules from "node_modules").
But if you find a better location feel free. :)