diff --git a/src/annotation/lazy_service_identifier.ts b/src/annotation/lazy_service_identifier.ts index c3f0106b2..c0ed2bf33 100644 --- a/src/annotation/lazy_service_identifier.ts +++ b/src/annotation/lazy_service_identifier.ts @@ -1,8 +1,8 @@ import { interfaces } from '../interfaces/interfaces'; -export type ServiceIdentifierOrFunc = interfaces.ServiceIdentifier | LazyServiceIdentifer; +export type ServiceIdentifierOrFunc = interfaces.ServiceIdentifier | LazyServiceIdentifier; -export class LazyServiceIdentifer { +export class LazyServiceIdentifier { private _cb: () => interfaces.ServiceIdentifier; public constructor(cb: () => interfaces.ServiceIdentifier) { this._cb = cb; diff --git a/src/constants/error_msgs.ts b/src/constants/error_msgs.ts index 5a8d7d7a6..901c2f50b 100644 --- a/src/constants/error_msgs.ts +++ b/src/constants/error_msgs.ts @@ -9,7 +9,7 @@ export const MISSING_INJECTABLE_ANNOTATION = 'Missing required @injectable annot export const MISSING_INJECT_ANNOTATION = 'Missing required @inject or @multiInject annotation in:'; export const UNDEFINED_INJECT_ANNOTATION = (name: string) => `@inject called with undefined this could mean that the class ${name} has ` + - 'a circular dependency problem. You can use a LazyServiceIdentifer to ' + + 'a circular dependency problem. You can use a LazyServiceIdentifier to ' + 'overcome this limitation.'; export const CIRCULAR_DEPENDENCY = 'Circular dependency found:'; export const NOT_IMPLEMENTED = 'Sorry, this feature is not fully implemented yet.'; diff --git a/src/inversify.ts b/src/inversify.ts index d2ae7e8c9..e79b2a427 100644 --- a/src/inversify.ts +++ b/src/inversify.ts @@ -8,7 +8,8 @@ export { injectable } from './annotation/injectable'; export { tagged } from './annotation/tagged'; export { named } from './annotation/named'; export { inject } from './annotation/inject'; -export { LazyServiceIdentifer } from './annotation/lazy_service_identifier' +export { LazyServiceIdentifier } from './annotation/lazy_service_identifier' +export { LazyServiceIdentifier as LazyServiceIdentifer } from './annotation/lazy_service_identifier' export { optional } from './annotation/optional'; export { unmanaged } from './annotation/unmanaged'; export { multiInject } from './annotation/multi_inject'; diff --git a/src/planning/reflection_utils.ts b/src/planning/reflection_utils.ts index 15147b065..d3a76a1ef 100644 --- a/src/planning/reflection_utils.ts +++ b/src/planning/reflection_utils.ts @@ -1,4 +1,4 @@ -import { LazyServiceIdentifer } from '../annotation/lazy_service_identifier'; +import { LazyServiceIdentifier } from '../annotation/lazy_service_identifier'; import * as ERROR_MSGS from '../constants/error_msgs'; import { TargetTypeEnum } from '../constants/literal_types'; import * as METADATA_KEY from '../constants/metadata_keys'; @@ -79,8 +79,8 @@ function getConstructorArgsAsTarget( const injectIdentifier = metadata.inject || metadata.multiInject; serviceIdentifier = (injectIdentifier ? injectIdentifier : serviceIdentifier) as interfaces.ServiceIdentifier | undefined; - // we unwrap LazyServiceIdentifer wrappers to allow circular dependencies on symbols - if (serviceIdentifier instanceof LazyServiceIdentifer) { + // we unwrap LazyServiceIdentifier wrappers to allow circular dependencies on symbols + if (serviceIdentifier instanceof LazyServiceIdentifier) { serviceIdentifier = serviceIdentifier.unwrap(); } diff --git a/test/annotation/inject.test.ts b/test/annotation/inject.test.ts index b2dace052..7627e68ce 100644 --- a/test/annotation/inject.test.ts +++ b/test/annotation/inject.test.ts @@ -9,7 +9,7 @@ declare function __param(paramIndex: number, decorator: ParameterDecorator): Cla import { expect } from 'chai'; import { decorate } from '../../src/annotation/decorator_utils'; import { inject } from '../../src/annotation/inject'; -import { LazyServiceIdentifer, ServiceIdentifierOrFunc } from '../../src/annotation/lazy_service_identifier'; +import { LazyServiceIdentifier, ServiceIdentifierOrFunc } from '../../src/annotation/lazy_service_identifier'; import * as ERROR_MSGS from '../../src/constants/error_msgs'; import * as METADATA_KEY from '../../src/constants/metadata_keys'; import { interfaces } from '../../src/interfaces/interfaces'; @@ -22,7 +22,7 @@ class Katana implements Katana { } class Shuriken implements Shuriken { } class Sword implements Sword { } -const lazySwordId = new LazyServiceIdentifer(() => 'Sword'); +const lazySwordId = new LazyServiceIdentifier(() => 'Sword'); class DecoratedWarrior { @@ -204,7 +204,7 @@ describe('@inject', () => { }).to.throw(`${ERROR_MSGS.UNDEFINED_INJECT_ANNOTATION('WithUndefinedInject')}`) }); - it('Should unwrap LazyServiceIdentifer', () => { + it('Should unwrap LazyServiceIdentifier', () => { const unwrapped = lazySwordId.unwrap(); expect(unwrapped).to.be.equal('Sword'); }); diff --git a/test/inversify.test.ts b/test/inversify.test.ts index e15cb1788..6a14d3ee1 100644 --- a/test/inversify.test.ts +++ b/test/inversify.test.ts @@ -1,7 +1,7 @@ import { expect } from 'chai'; import * as ERROR_MSGS from '../src/constants/error_msgs'; import { interfaces } from '../src/interfaces/interfaces'; -import { Container, ContainerModule, decorate, inject, injectable, LazyServiceIdentifer, multiInject, named, tagged, targetName, typeConstraint, unmanaged } from '../src/inversify'; +import { Container, ContainerModule, decorate, inject, injectable, LazyServiceIdentifier, multiInject, named, tagged, targetName, typeConstraint, unmanaged } from '../src/inversify'; describe('InversifyJS', () => { @@ -282,7 +282,7 @@ describe('InversifyJS', () => { }); - it('Should be able to wrap Symbols with LazyServiceIdentifer', () => { + it('Should be able to wrap Symbols with LazyServiceIdentifier', () => { interface Ninja { fight(): string; @@ -324,8 +324,8 @@ describe('InversifyJS', () => { private _shuriken: Shuriken; public constructor( - @inject(new LazyServiceIdentifer(() => TYPES.Katana)) katana: Katana, - @inject(new LazyServiceIdentifer(() => TYPES.Shuriken)) shuriken: Shuriken + @inject(new LazyServiceIdentifier(() => TYPES.Katana)) katana: Katana, + @inject(new LazyServiceIdentifier(() => TYPES.Shuriken)) shuriken: Shuriken ) { this._katana = katana; this._shuriken = shuriken; diff --git a/test/utils/reflection.test.ts b/test/utils/reflection.test.ts index 7b5980e51..4dea8a246 100644 --- a/test/utils/reflection.test.ts +++ b/test/utils/reflection.test.ts @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { injectable, inject, LazyServiceIdentifer, Container } from '../../src/inversify'; +import { injectable, inject, LazyServiceIdentifier, Container } from '../../src/inversify'; import { getDependencies } from '../../src/planning/reflection_utils'; import { MetadataReader } from "../../src/planning/metadata_reader"; import sinon from "sinon"; @@ -34,7 +34,7 @@ describe('Reflection Utilities Unit Tests', () => { private _katana: Katana; public constructor( - @inject(new LazyServiceIdentifer(() => TYPES.Katana)) katana: Katana, + @inject(new LazyServiceIdentifier(() => TYPES.Katana)) katana: Katana, ) { this._katana = katana; } @@ -47,7 +47,7 @@ describe('Reflection Utilities Unit Tests', () => { container.bind(TYPES.Ninja).to(Ninja); container.bind(TYPES.Katana).to(Katana); - const unwrapSpy = sinon.spy(LazyServiceIdentifer.prototype, 'unwrap'); + const unwrapSpy = sinon.spy(LazyServiceIdentifier.prototype, 'unwrap'); const dependencies = getDependencies(new MetadataReader(), Ninja); diff --git a/wiki/circular_dependencies.md b/wiki/circular_dependencies.md index df330919a..6dadf860e 100644 --- a/wiki/circular_dependencies.md +++ b/wiki/circular_dependencies.md @@ -4,11 +4,11 @@ If you have a circular dependency between two modules and you use the `@inject(SomeClass)` annotation. At runtime, one module will be parsed before the other and the decorator could be invoked with `@inject(SomeClass /* SomeClass = undefined*/)`. InversifyJS will throw the following exception: -> @inject called with undefined this could mean that the class ${name} has a circular dependency problem. You can use a LazyServiceIdentifer to overcome this limitation. +> @inject called with undefined this could mean that the class ${name} has a circular dependency problem. You can use a LazyServiceIdentifier to overcome this limitation. There are two ways to overcome this limitation: -- Use a `LazyServiceIdentifer`. The lazy identifier doesn't delay the injection of the dependencies and all dependencies are injected when the class instance is created. However, it does delay the access to the property identifier (solving the module issue). An example of this can be found in [our unit tests](https://github.com/krzkaczor/InversifyJS/blob/a53bf2cbee65803b197998c1df496c3be84731d9/test/inversify.test.ts#L236-L300). +- Use a `LazyServiceIdentifier`. The lazy identifier doesn't delay the injection of the dependencies and all dependencies are injected when the class instance is created. However, it does delay the access to the property identifier (solving the module issue). An example of this can be found in [our unit tests](https://github.com/krzkaczor/InversifyJS/blob/a53bf2cbee65803b197998c1df496c3be84731d9/test/inversify.test.ts#L236-L300). - Use the `@lazyInject` decorator. This decorator is part of the [`inversify-inject-decorators`](https://github.com/inversify/inversify-inject-decorators) module. The `@lazyInject` decorator delays the injection of the dependencies until they are actually used, this takes place after a class instance has been created. diff --git a/wiki/container_api.md b/wiki/container_api.md index fb825ddf1..29b7ba3b6 100644 --- a/wiki/container_api.md +++ b/wiki/container_api.md @@ -559,7 +559,7 @@ Restore container state to last snapshot. Save the state of the container to be later restored with the restore method. ## container.unbind(serviceIdentifier: interfaces.ServiceIdentifier\): void -Remove all bindings binded in this container to the service identifer. This will result in the [deactivation process](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md). +Remove all bindings binded in this container to the service identifier. This will result in the [deactivation process](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md). ## container.unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier\): Promise\ diff --git a/wiki/deactivation_handler.md b/wiki/deactivation_handler.md index 9dbdc339d..d27cd6887 100644 --- a/wiki/deactivation_handler.md +++ b/wiki/deactivation_handler.md @@ -24,7 +24,7 @@ It's possible to add a deactivation handler in multiple ways - Adding the handler to a binding. - Adding the handler to the class through the [preDestroy decorator](./pre_destroy.md). -Handlers added to the container are the first ones to be resolved. Any handler added to a child container is called before the ones added to their parent. Relevant bindings from the container are called next and finally the `preDestroy` method is called. In the example above, relevant bindings are those bindings bound to the unbinded "Destroyable" service identifer. +Handlers added to the container are the first ones to be resolved. Any handler added to a child container is called before the ones added to their parent. Relevant bindings from the container are called next and finally the `preDestroy` method is called. In the example above, relevant bindings are those bindings bound to the unbinded "Destroyable" service identifier. The example below demonstrates call order.