Skip to content

Commit

Permalink
Merge branch 'master' into dc/fix-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Jameskmonger authored Sep 12, 2023
2 parents 577c316 + eecf9bf commit fe804df
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 21 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/readiing-time.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Reading Time

on:
workflow_dispatch:
push:
branches:
- master
paths:
- "**.md"

jobs:
calculate-reading-time:
runs-on: ubuntu-latest
name: Calculate Reading Time
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Calculate & Prepend Reading Time
uses: harunrst/[email protected]
with:
strategy: all

- name: Commit Changes
uses: EndBug/add-and-commit@v9
with:
message: Edited markdown files with reading times.
push: false

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
with:
title: Update markdown files with reading time.
body: Auto-generated Pull Request by [reading-time-action](https://github.com/harunrst/reading-time-action).
branch: reading-time-action
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

0 comments on commit fe804df

Please sign in to comment.