Rework global registry to be per-module-instance

Fix a regression introduced by b917075 where two loopback projects,
each one using a different instance of loopback module, were
sharing the global registry and thus not working correctly.

The issue was discovered by unit-tests in loopback-workspace.
This commit is contained in:
Miroslav Bajtoš 2015-04-17 19:21:50 +02:00
parent 73ee01f27c
commit f130b7aa01
2 changed files with 2 additions and 12 deletions

View File

@ -1,8 +0,0 @@
module.exports = function() {
var Registry = require('./registry');
var registry = global.__LOOPBACK_GLOBAL_REGISTRY__;
if (!registry) {
registry = global.__LOOPBACK_GLOBAL_REGISTRY__ = new Registry();
}
return registry;
};

View File

@ -11,7 +11,6 @@ var path = require('path');
var merge = require('util')._extend; var merge = require('util')._extend;
var assert = require('assert'); var assert = require('assert');
var Registry = require('./registry'); var Registry = require('./registry');
var getGlobalRegistry = require('./global-registry');
var juggler = require('loopback-datasource-juggler'); var juggler = require('loopback-datasource-juggler');
/** /**
@ -49,10 +48,9 @@ loopback.version = require('../package.json').version;
loopback.mime = express.mime; loopback.mime = express.mime;
loopback.registry = new Registry();
Object.defineProperties(loopback, { Object.defineProperties(loopback, {
registry: {
get: getGlobalRegistry
},
Model: { Model: {
get: function() { return this.registry.getModel('Model'); } get: function() { return this.registry.getModel('Model'); }
}, },