dependency-injection
Advanced tools
Comparing version 2.1.1 to 2.2.0
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var DI, Helpers, Service, | ||
var DI, Defaults, Helpers, Service, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
@@ -10,2 +10,4 @@ | ||
Defaults = require('./Defaults'); | ||
DI = (function() { | ||
@@ -27,10 +29,6 @@ DI.prototype.services = null; | ||
function DI() { | ||
var di; | ||
di = new Service(this, 'di', this); | ||
di.instantiate = false; | ||
this.services = { | ||
di: di | ||
}; | ||
this.services = {}; | ||
this.paths = {}; | ||
this.creating = []; | ||
new Defaults(this); | ||
} | ||
@@ -53,3 +51,3 @@ | ||
} | ||
if (__indexOf.call(this.reserved, name) >= 0) { | ||
if (__indexOf.call(this.reserved, name) >= 0 && typeof this.services[name] !== 'undefined') { | ||
throw new Error("DI: name '" + name + "' is reserved by DI."); | ||
@@ -56,0 +54,0 @@ } |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Configuration, DI, DIConfigurator; | ||
var Configuration, DI, DIConfigurator, callsite, isWindow, path; | ||
@@ -9,2 +9,9 @@ DI = require('./DI'); | ||
isWindow = typeof window !== 'undefined'; | ||
if (!isWindow) { | ||
callsite = require('callsite'); | ||
path = require('path'); | ||
} | ||
DIConfigurator = (function() { | ||
@@ -17,2 +24,4 @@ DIConfigurator.EXPOSE_NAME = 'di'; | ||
DIConfigurator.prototype.basePath = null; | ||
DIConfigurator.prototype.defaultSetup = { | ||
@@ -32,4 +41,20 @@ windowExpose: null, | ||
function DIConfigurator(path) { | ||
this.path = path; | ||
function DIConfigurator(pathOrConfig) { | ||
var stack; | ||
if (typeof pathOrConfig === 'string') { | ||
if (pathOrConfig[0] === '.' && isWindow) { | ||
throw new Error('Relative paths to config files are not supported in browser.'); | ||
} | ||
if (pathOrConfig[0] === '.') { | ||
stack = callsite(); | ||
this.basePath = path.dirname(stack[1].getFileName()); | ||
pathOrConfig = path.join(this.basePath, pathOrConfig); | ||
} | ||
this.path = pathOrConfig; | ||
this.config = new Configuration(this.path); | ||
} else if (pathOrConfig instanceof Configuration) { | ||
this.config = pathOrConfig; | ||
} else { | ||
throw new Error('Bad argument'); | ||
} | ||
} | ||
@@ -39,3 +64,2 @@ | ||
var configuration, defaultService, defaultSetup, di, expose, method, name, run, s, service, _i, _len, _ref, _ref1; | ||
this.config = new Configuration(this.path); | ||
defaultService = this.defaultService; | ||
@@ -58,2 +82,5 @@ this.config.addSection('services').loadConfiguration = function() { | ||
di = new DI; | ||
if (this.basePath !== null) { | ||
di.basePath = this.basePath; | ||
} | ||
di.config = this.config; | ||
@@ -60,0 +87,0 @@ di.parameters = this.config.parameters; |
{ | ||
"name": "dependency-injection", | ||
"description": "Dependency injection with configuration and autowire for node js and browser", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"author": { | ||
@@ -25,9 +25,10 @@ "name": "David Kudera", | ||
"dependencies": { | ||
"easy-configuration": "1.6.6" | ||
"easy-configuration": "~2.0.0", | ||
"callsite": "~1.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "1.8.1", | ||
"mocha": "1.16.2", | ||
"mocha-phantomjs": "3.3.0", | ||
"phantomjs": "1.9.2-6" | ||
"chai": "~1.8.1", | ||
"mocha": "~1.16.2", | ||
"mocha-phantomjs": "~3.3.1", | ||
"phantomjs": "~1.9.2-6" | ||
}, | ||
@@ -34,0 +35,0 @@ "scripts": { |
@@ -28,5 +28,6 @@ [![NPM version](https://badge.fury.io/js/dependency-injection.png)](http://badge.fury.io/js/dependency-injection) | ||
You can see full documentation of easy-configuration [here](https://npmjs.org/package/easy-configuration). This package | ||
is used for configuration your services (classes). | ||
Please first read full documentation of [easy-configuration](https://github.com/sakren/node-easy-configuration). It will | ||
really help you. | ||
``` | ||
@@ -59,8 +60,9 @@ { | ||
var DIConfigurator = require('dependency-injection/DIConfigurator'); | ||
var configurator = new DIConfigurator('/path/to/your/configuration/file.json'); | ||
var configurator = new DIConfigurator('./path/to/your/configuration/file.json'); | ||
var di = configurator.create(); | ||
di.basePath = __dirname; | ||
``` | ||
**Relative paths to config files are supported only on node (not in browser)!!!** | ||
This will create new instance of DI class which holding all your services. | ||
@@ -79,2 +81,10 @@ | ||
## Base path to services | ||
Default base path in node is directory of file from which you are initializing DI. You have to set this manually in browser. | ||
``` | ||
di.basePath = __dirname; | ||
``` | ||
## Auto exposing into global | ||
@@ -340,7 +350,12 @@ | ||
## Autowiring DI | ||
## Default services | ||
Autowiring DI container is also possible. Only thing you need to do, is set argument with name "di" into your method or | ||
constructor. This also means that you can not register new service with name "di". | ||
There are already prepared some services. | ||
* `di`: di container itself | ||
* `timer`: object with `setTimeout`, `setInterval`, `clearTimeout` and `clearInterval` methods | ||
* `window`: window object (browser only) | ||
* `document`: window.document object (browser only) | ||
* `global`: global object (node.js only) | ||
``` | ||
@@ -387,2 +402,18 @@ di.get('di'); | ||
## Advanced configuration | ||
If you need more control over configuration, you can create instance of `easy-configuration` object on your own and pass | ||
it to DIConfigurator. | ||
``` | ||
var Config = require('easy-configuration'); | ||
var DIConfigurator = require('dependency-injection/DIConfigurator'); | ||
var config = new Config; | ||
config.addConfig('./path/to/config.json', 'development'); | ||
var configurator = new DIConfigurator(config); | ||
var di = configurator.create(); | ||
``` | ||
## Without configuration | ||
@@ -452,2 +483,9 @@ | ||
* 2.2.0 | ||
+ Relative paths to config files | ||
+ Little updates in tests | ||
+ Added default services | ||
+ Better documentation | ||
+ Many improvements in configuration (see [easy-configuration](https://github.com/sakren/node-easy-configuration)) | ||
* 2.1.1 | ||
@@ -454,0 +492,0 @@ + Hints has exactly the same syntax as arguments configuration |
@@ -1,9 +0,3 @@ | ||
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
require('./Helpers'); | ||
require('./DI'); | ||
require('./DIConfigurator'); | ||
}).call(this); | ||
require('./lib/Helpers'); | ||
require('./lib/DI'); | ||
require('./lib/DIConfigurator'); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
180971
40
3096
591
2
+ Addedcallsite@~1.0.0
+ Addedcallsite@1.0.0(transitive)
+ Addedeasy-configuration@2.0.2(transitive)
- Removedeasy-configuration@1.6.6(transitive)
Updatedeasy-configuration@~2.0.0