diff --git a/packages/ioc/index.ts b/packages/ioc/index.ts new file mode 100644 index 000000000000..3e8733ce6631 --- /dev/null +++ b/packages/ioc/index.ts @@ -0,0 +1,7 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: loopback +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +export {Binding} from './src/binding'; +export {Context} from './src/context'; diff --git a/packages/ioc/package.json b/packages/ioc/package.json new file mode 100644 index 000000000000..ebf0fee529e7 --- /dev/null +++ b/packages/ioc/package.json @@ -0,0 +1,28 @@ +{ + "name": "@loopback/ioc", + "version": "4.0.0-alpha.1", + "description": "LoopBack's container for Inversion of Control", + "main": "index", + "scripts": { + "acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'", + "integration": "mocha --opts ../../test/mocha.opts 'test/integration/**/*.ts'", + "test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/integration/**/*.ts' 'test/acceptance/**/*.ts'", + "unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'" + }, + "author": "IBM", + "license": "MIT", + "dependencies": { + }, + "devDependencies": { + "@loopback/testlab": "^4.0.0-alpha.1", + "mocha": "^3.2.0" + }, + "keywords": [ + "LoopBack", + "IoC", + "Inversion", + "Control", + "Container", + "Decorators" + ] +} diff --git a/packages/loopback/lib/context/binding.ts b/packages/ioc/src/binding.ts similarity index 100% rename from packages/loopback/lib/context/binding.ts rename to packages/ioc/src/binding.ts diff --git a/packages/loopback/lib/context/index.ts b/packages/ioc/src/context.ts similarity index 100% rename from packages/loopback/lib/context/index.ts rename to packages/ioc/src/context.ts diff --git a/packages/loopback/test/acceptance/context-bindings/_feature.md b/packages/ioc/test/acceptance/_feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/_feature.md rename to packages/ioc/test/acceptance/_feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/creating-and-resolving-bindings.feature.md b/packages/ioc/test/acceptance/creating-and-resolving-bindings.feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/creating-and-resolving-bindings.feature.md rename to packages/ioc/test/acceptance/creating-and-resolving-bindings.feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/creating-and-resolving-bindings.ts b/packages/ioc/test/acceptance/creating-and-resolving-bindings.ts similarity index 96% rename from packages/loopback/test/acceptance/context-bindings/creating-and-resolving-bindings.ts rename to packages/ioc/test/acceptance/creating-and-resolving-bindings.ts index 49c18a0a3c96..67e29f5d9964 100644 --- a/packages/loopback/test/acceptance/context-bindings/creating-and-resolving-bindings.ts +++ b/packages/ioc/test/acceptance/creating-and-resolving-bindings.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import * as util from 'loopback/test/support/util'; +import {Context} from '../..'; describe('Context bindings - Creating and resolving bindings', () => { let ctx; @@ -68,6 +68,6 @@ describe('Context bindings - Creating and resolving bindings', () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } }); diff --git a/packages/loopback/test/acceptance/context-bindings/finding-bindings.feature.md b/packages/ioc/test/acceptance/finding-bindings.feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/finding-bindings.feature.md rename to packages/ioc/test/acceptance/finding-bindings.feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/finding-bindings.ts b/packages/ioc/test/acceptance/finding-bindings.ts similarity index 96% rename from packages/loopback/test/acceptance/context-bindings/finding-bindings.ts rename to packages/ioc/test/acceptance/finding-bindings.ts index c0296a369da0..333b791575e5 100644 --- a/packages/loopback/test/acceptance/context-bindings/finding-bindings.ts +++ b/packages/ioc/test/acceptance/finding-bindings.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import * as util from 'loopback/test/support/util'; +import {Context} from '../..'; describe('Context bindings - Finding bindings', () => { let ctx; @@ -66,7 +66,7 @@ describe('Context bindings - Finding bindings', () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } function createBinding(key, value) { ctx.bind(key).to(value); diff --git a/packages/loopback/test/acceptance/context-bindings/locking-bindings.feature.md b/packages/ioc/test/acceptance/locking-bindings.feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/locking-bindings.feature.md rename to packages/ioc/test/acceptance/locking-bindings.feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/locking-bindings.ts b/packages/ioc/test/acceptance/locking-bindings.ts similarity index 94% rename from packages/loopback/test/acceptance/context-bindings/locking-bindings.ts rename to packages/ioc/test/acceptance/locking-bindings.ts index 810013fd5917..b7f2a5924c40 100644 --- a/packages/loopback/test/acceptance/context-bindings/locking-bindings.ts +++ b/packages/ioc/test/acceptance/locking-bindings.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import * as util from 'loopback/test/support/util'; +import {Context} from '../..'; describe('Context bindings - Locking bindings', () => { describe('Binding with a duplicate key', () => { @@ -45,7 +45,7 @@ describe('Context bindings - Locking bindings', () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } function createBinding() { binding = ctx.bind('foo'); diff --git a/packages/loopback/test/acceptance/context-bindings/tagged-bindings.feature.md b/packages/ioc/test/acceptance/tagged-bindings.feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/tagged-bindings.feature.md rename to packages/ioc/test/acceptance/tagged-bindings.feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/tagged-bindings.ts b/packages/ioc/test/acceptance/tagged-bindings.ts similarity index 90% rename from packages/loopback/test/acceptance/context-bindings/tagged-bindings.ts rename to packages/ioc/test/acceptance/tagged-bindings.ts index 85c268eee31b..c06ab321a96e 100644 --- a/packages/loopback/test/acceptance/context-bindings/tagged-bindings.ts +++ b/packages/ioc/test/acceptance/tagged-bindings.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import * as util from 'loopback/test/support/util'; +import {Context} from '../..'; describe('Context bindings - Tagged bindings', () => { let ctx; @@ -27,7 +27,7 @@ describe('Context bindings - Tagged bindings', () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } function createBinding() { binding = ctx.bind('foo').to('bar'); diff --git a/packages/loopback/test/acceptance/context-bindings/unlocking-bindings.feature.md b/packages/ioc/test/acceptance/unlocking-bindings.feature.md similarity index 100% rename from packages/loopback/test/acceptance/context-bindings/unlocking-bindings.feature.md rename to packages/ioc/test/acceptance/unlocking-bindings.feature.md diff --git a/packages/loopback/test/acceptance/context-bindings/unlocking-bindings.ts b/packages/ioc/test/acceptance/unlocking-bindings.ts similarity index 94% rename from packages/loopback/test/acceptance/context-bindings/unlocking-bindings.ts rename to packages/ioc/test/acceptance/unlocking-bindings.ts index 44931749bbb0..a1f72dd15525 100644 --- a/packages/loopback/test/acceptance/context-bindings/unlocking-bindings.ts +++ b/packages/ioc/test/acceptance/unlocking-bindings.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import * as util from 'loopback/test/support/util'; +import {Context} from '../..'; describe(`Context bindings - Unlocking bindings`, () => { describe('Unlocking a locked binding', () => { @@ -43,7 +43,7 @@ describe(`Context bindings - Unlocking bindings`, () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } function createLockedBinding() { binding = ctx.bind('foo').to('bar'); diff --git a/packages/loopback/test/unit/context/binding.ts b/packages/ioc/test/unit/binding.ts similarity index 93% rename from packages/loopback/test/unit/context/binding.ts rename to packages/ioc/test/unit/binding.ts index ef12548c509e..5a575305aa78 100644 --- a/packages/loopback/test/unit/context/binding.ts +++ b/packages/ioc/test/unit/binding.ts @@ -4,7 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import {Binding} from 'loopback/lib/context/binding'; +import {Binding} from '../..'; const key = 'foo'; const binding = new Binding(key); diff --git a/packages/loopback/test/unit/context/index.ts b/packages/ioc/test/unit/context.ts similarity index 89% rename from packages/loopback/test/unit/context/index.ts rename to packages/ioc/test/unit/context.ts index c6dd6a3923c7..13265d7e0308 100644 --- a/packages/loopback/test/unit/context/index.ts +++ b/packages/ioc/test/unit/context.ts @@ -4,8 +4,7 @@ // License text available at https://opensource.org/licenses/MIT import {expect} from 'testlab'; -import {Binding} from 'loopback/lib/context/binding'; -import * as util from 'loopback/test/support/util'; +import {Context, Binding} from '../..'; describe('Context', () => { let ctx; @@ -43,6 +42,6 @@ describe('Context', () => { }); function createContext() { - ctx = util.getContext(); + ctx = new Context(); } }); diff --git a/packages/loopback/lib/application.ts b/packages/loopback/lib/application.ts index eebff6de985b..5f3e9d1e6b1e 100644 --- a/packages/loopback/lib/application.ts +++ b/packages/loopback/lib/application.ts @@ -3,8 +3,7 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT -import {Binding} from './context/binding'; -import {Context} from './context'; +import {Binding, Context} from '@loopback/ioc'; import * as http from 'http'; import {SwaggerRouter} from './router/SwaggerRouter'; import {getApiSpec} from './router/metadata'; diff --git a/packages/loopback/lib/server.ts b/packages/loopback/lib/server.ts index 39b2d5f1d112..c48117006087 100644 --- a/packages/loopback/lib/server.ts +++ b/packages/loopback/lib/server.ts @@ -5,7 +5,7 @@ import http = require('http'); import bluebird = require('bluebird'); -import {Context} from './context'; +import {Context} from '@loopback/ioc'; import {Application} from '../lib/application'; import {SwaggerRouter} from './router/SwaggerRouter'; diff --git a/packages/loopback/package.json b/packages/loopback/package.json index 4344b9aacbc2..12d58d1548b7 100644 --- a/packages/loopback/package.json +++ b/packages/loopback/package.json @@ -12,6 +12,7 @@ "author": "IBM", "license": "MIT", "dependencies": { + "@loopback/ioc": "^4.0.0-alpha.1", "@loopback/juggler": "^4.0.0-alpha.1", "@loopback/remoting": "^4.0.0-alpha.1", "body": "^5.1.0", diff --git a/packages/loopback/test/support/util.ts b/packages/loopback/test/support/util.ts index 69c08dc8b4e3..7143e1526b98 100644 --- a/packages/loopback/test/support/util.ts +++ b/packages/loopback/test/support/util.ts @@ -5,7 +5,7 @@ import {Application, Server, ServerConfig} from 'loopback'; import {Client} from './client'; -import {Context} from '../../lib/context'; +import {Context} from '@loopback/ioc'; import * as bluebird from 'bluebird'; import * as http from 'http';