Comments (4)
The service name is resolved explicitly unless there is no such service. In that case, it'll assume that the service name is actually a prefix and will try to find all services that share this prefix.
So the examples you've shown are actually all exactly as I'd expect them.
I agree with you however, that the full name thing is ugly. Especially for constructor/function injection. pioc supports AngularJS style annotations, so you could (if you really wanted to) wrap the last case like this:
injector.resolve(['services_consoleService', function(consoleService) {
// ...
}]);
But that is really only ever practical for client side use.
For my own code, I try to use property injection instead of constructor injection whenever possible as it doesn't have the issues around minification on the client side and is more explicit.
If you have a proposal for a better handling for constructor/function injection, I'm all ears. I'll invest some time as well to try to come up with a better solution.
from pioc.
I understand now, thank you.
What do you think of adding something like 'namespace' in service name? For example:
var module = pioc.createModule()
.bind('services/groupA/consoleService', require('./services/consoleService.js'))
.bind('services/groupA/dummyService', require('./services/dummyService.js'))
.bind('services/groupB/anotherService', require('./services/anotherService.js'))
.bind('name/consoleService', require('./services/consoleService.js'))
...
injector.resolve(function (services) {
console.log(util.inspect(services)); // Array[3] (console, dummy and another)
});
injector.resolve(function (groupA) {
console.log(util.inspect(groupA)); // Array[2] - (console, dummy)
});
injector.resolve(function (consoleService) {
console.log(util.inspect(services_consoleService)); // Array[2] - (consoleService from services/, consoleService from name/)
});
However, I'm not sure if this is a good solution.
The simple solution maybe is to allow to find service by name, ignoring the prefix, when the search by "prefix" result in nothing
from pioc.
Sorry, was busy at work.
I believe that namespaces are too much, however, I agree that at least a suffix search should be performed before giving up.
In the end, the task of a DIC is to resolve dependencies and resolving to something should be the default behaviour (and in most cases should be preferable to failing). However, I'd like to add some configuration options to it so that the various fallback behaviours can be disabled.
from pioc.
Behaviour has been implemented in v1.3.0 (just released).
from pioc.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pioc.