Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typo (LazyServiceIdentifer -> LazyServiceIdentifier) #1483

Merged
merged 5 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/annotation/lazy_service_identifier.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { interfaces } from '../interfaces/interfaces';

export type ServiceIdentifierOrFunc<T> = interfaces.ServiceIdentifier<T> | LazyServiceIdentifer<T>;
export type ServiceIdentifierOrFunc<T> = interfaces.ServiceIdentifier<T> | LazyServiceIdentifier<T>;

export class LazyServiceIdentifer<T = unknown> {
export class LazyServiceIdentifier<T = unknown> {
private _cb: () => interfaces.ServiceIdentifier<T>;
public constructor(cb: () => interfaces.ServiceIdentifier<T>) {
this._cb = cb;
Expand Down
2 changes: 1 addition & 1 deletion src/constants/error_msgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
3 changes: 2 additions & 1 deletion src/inversify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
6 changes: 3 additions & 3 deletions src/planning/reflection_utils.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -79,8 +79,8 @@ function getConstructorArgsAsTarget(
const injectIdentifier = metadata.inject || metadata.multiInject;
serviceIdentifier = (injectIdentifier ? injectIdentifier : serviceIdentifier) as interfaces.ServiceIdentifier<unknown> | 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();
}

Expand Down
6 changes: 3 additions & 3 deletions test/annotation/inject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {

Expand Down Expand Up @@ -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');
});
Expand Down
8 changes: 4 additions & 4 deletions test/inversify.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions test/utils/reflection.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
Expand All @@ -47,7 +47,7 @@ describe('Reflection Utilities Unit Tests', () => {
container.bind<Ninja>(TYPES.Ninja).to(Ninja);
container.bind<Katana>(TYPES.Katana).to(Katana);

const unwrapSpy = sinon.spy(LazyServiceIdentifer.prototype, 'unwrap');
const unwrapSpy = sinon.spy(LazyServiceIdentifier.prototype, 'unwrap');

const dependencies = getDependencies(new MetadataReader(), Ninja);

Expand Down
4 changes: 2 additions & 2 deletions wiki/circular_dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion wiki/container_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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\<unknown>): 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\<unknown>): Promise\<void>

Expand Down
2 changes: 1 addition & 1 deletion wiki/deactivation_handler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Loading