From 579f857f822eef990a2f9520128120c103c240fe Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 29 Apr 2017 22:34:10 -0400 Subject: [PATCH] Remove factory injections. These were only around to support `lookupFactory` semantics. --- packages/container/lib/registry.js | 143 ---------------------- packages/container/tests/registry_test.js | 23 ---- 2 files changed, 166 deletions(-) diff --git a/packages/container/lib/registry.js b/packages/container/lib/registry.js index 3d9ba5016bd..ae62b7b791a 100644 --- a/packages/container/lib/registry.js +++ b/packages/container/lib/registry.js @@ -32,8 +32,6 @@ export default function Registry(options) { this._typeInjections = dictionary(null); this._injections = dictionary(null); - this._factoryTypeInjections = dictionary(null); - this._factoryInjections = dictionary(null); this._localLookupCache = Object.create(null); this._normalizeCache = dictionary(null); @@ -86,22 +84,6 @@ Registry.prototype = { */ _injections: null, - /** - @private - - @property _factoryTypeInjections - @type InheritingDict - */ - _factoryTypeInjections: null, - - /** - @private - - @property _factoryInjections - @type InheritingDict - */ - _factoryInjections: null, - /** @private @@ -549,115 +531,6 @@ Registry.prototype = { }); }, - - /** - Used only via `factoryInjection`. - - Provides a specialized form of injection, specifically enabling - all factory of one type to be injected with a reference to another - object. - - For example, provided each factory of type `model` needed a `store`. - one would do the following: - - ```javascript - let registry = new Registry(); - - registry.register('store:main', SomeStore); - - registry.factoryTypeInjection('model', 'store', 'store:main'); - - let store = registry.lookup('store:main'); - let UserFactory = registry.lookupFactory('model:user'); - - UserFactory.store instanceof SomeStore; //=> true - ``` - - @private - @method factoryTypeInjection - @param {String} type - @param {String} property - @param {String} fullName - */ - factoryTypeInjection(type, property, fullName) { - let injections = this._factoryTypeInjections[type] || - (this._factoryTypeInjections[type] = []); - - injections.push({ - property: property, - fullName: this.normalize(fullName) - }); - }, - - /** - Defines factory injection rules. - - Similar to regular injection rules, but are run against factories, via - `Registry#lookupFactory`. - - These rules are used to inject objects onto factories when they - are looked up. - - Two forms of injections are possible: - - * Injecting one fullName on another fullName - * Injecting one fullName on a type - - Example: - - ```javascript - let registry = new Registry(); - let container = registry.container(); - - registry.register('store:main', Store); - registry.register('store:secondary', OtherStore); - registry.register('model:user', User); - registry.register('model:post', Post); - - // injecting one fullName on another type - registry.factoryInjection('model', 'store', 'store:main'); - - // injecting one fullName on another fullName - registry.factoryInjection('model:post', 'secondaryStore', 'store:secondary'); - - let UserFactory = container.lookupFactory('model:user'); - let PostFactory = container.lookupFactory('model:post'); - let store = container.lookup('store:main'); - - UserFactory.store instanceof Store; //=> true - UserFactory.secondaryStore instanceof OtherStore; //=> false - - PostFactory.store instanceof Store; //=> true - PostFactory.secondaryStore instanceof OtherStore; //=> true - - // and both models share the same source instance - UserFactory.store === PostFactory.store; //=> true - ``` - - @private - @method factoryInjection - @param {String} factoryName - @param {String} property - @param {String} injectionName - */ - factoryInjection(fullName, property, injectionName) { - let normalizedName = this.normalize(fullName); - let normalizedInjectionName = this.normalize(injectionName); - - this.validateFullName(injectionName); - - if (fullName.indexOf(':') === -1) { - return this.factoryTypeInjection(normalizedName, property, normalizedInjectionName); - } - - let injections = this._factoryInjections[normalizedName] || (this._factoryInjections[normalizedName] = []); - - injections.push({ - property: property, - fullName: normalizedInjectionName - }); - }, - /** @private @method knownForType @@ -743,22 +616,6 @@ Registry.prototype = { injections = injections.concat(this.fallback.getTypeInjections(type)); } return injections; - }, - - getFactoryInjections(fullName) { - let injections = this._factoryInjections[fullName] || []; - if (this.fallback) { - injections = injections.concat(this.fallback.getFactoryInjections(fullName)); - } - return injections; - }, - - getFactoryTypeInjections(type) { - let injections = this._factoryTypeInjections[type] || []; - if (this.fallback) { - injections = injections.concat(this.fallback.getFactoryTypeInjections(type)); - } - return injections; } }; diff --git a/packages/container/tests/registry_test.js b/packages/container/tests/registry_test.js index b5071c6b69d..dda19296718 100644 --- a/packages/container/tests/registry_test.js +++ b/packages/container/tests/registry_test.js @@ -436,29 +436,6 @@ QUnit.test('`getTypeInjections` includes type injections from a fallback registr equal(registry.getTypeInjections('model').length, 1, 'Injections from the fallback registry are merged'); }); -QUnit.test('`getFactoryInjections` includes factory injections from a fallback registry', function() { - let fallback = new Registry(); - let registry = new Registry({ fallback: fallback }); - - equal(registry.getFactoryInjections('model:user').length, 0, 'No factory injections in the primary registry'); - - fallback.factoryInjection('model:user', 'store', 'store:main'); - - equal(registry.getFactoryInjections('model:user').length, 1, 'Factory injections from the fallback registry are merged'); -}); - - -QUnit.test('`getFactoryTypeInjections` includes factory type injections from a fallback registry', function() { - let fallback = new Registry(); - let registry = new Registry({ fallback: fallback }); - - equal(registry.getFactoryTypeInjections('model').length, 0, 'No factory type injections in the primary registry'); - - fallback.factoryInjection('model', 'store', 'store:main'); - - equal(registry.getFactoryTypeInjections('model').length, 1, 'Factory type injections from the fallback registry are merged'); -}); - QUnit.test('`knownForType` contains keys for each item of a given type', function() { let registry = new Registry();