Skip to content

Commit

Permalink
docs: remove inversify-inject-decorators references (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover authored Dec 14, 2024
1 parent f10c992 commit 8ddb3f6
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 64 deletions.
6 changes: 2 additions & 4 deletions wiki/circular_dependencies.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Circular dependencies

## Circular dependencies in your modules (ES6, CommonJS, etc.)
## Circular dependencies in your modules (ESM, CommonJS)

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 LazyServiceIdentifier to overcome this limitation.
There are two ways to overcome this limitation:
There's a way to overcome this limitation:

- 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.

## Circular dependencies in the dependency graph (classes)

InversifyJS is able to identify circular dependencies and will throw an exception to help you to identify the location of the problem if a circular dependency is detected:
Expand Down
10 changes: 3 additions & 7 deletions wiki/classes_as_id.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ An exception:
Will be thrown if we use classes as identifiers in circular dependencies. For example:

```ts
import { Container, injectable } from "inversify";
import getDecorators from "inversify-inject-decorators";
import { Container, injectable, inject } from "inversify";

let container = new Container();
let { lazyInject } = getDecorators(container);

@injectable()
class Dom {
Expand All @@ -82,7 +80,7 @@ class Dom {

@injectable()
class DomUi {
@lazyInject(Dom) public dom: Dom;
@inject(Dom) public dom: Dom;
}

@injectable()
Expand All @@ -103,10 +101,8 @@ The solution is to use symbols like `Symbol.for("Dom")` as service identifiers i

```ts
import { Container, injectable, inject } from "inversify";
import getDecorators from "inversify-inject-decorators";

const container: Container = new Container();
const { lazyInject } = getDecorators(container);

const TYPE = {
Dom: Symbol.for("Dom"),
Expand All @@ -128,7 +124,7 @@ class DomUi {
@injectable()
class Dom {
public name: string;
@lazyInject(TYPE.DomUi) public domUi: DomUi;
@inject(TYPE.DomUi) public domUi: DomUi;
constructor() {
this.name = "Dom";
}
Expand Down
1 change: 0 additions & 1 deletion wiki/ecosystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Consider these the “staff picks”, and don’t hesitate to submit a PR if you

### Utilities
- [inversify-binding-decorators](https://github.com/inversify/inversify-binding-decorators) - Allows developers to declare InversifyJS bindings using decorators.
- [inversify-inject-decorators](https://github.com/inversify/inversify-inject-decorators) - Allows developers to declare lazy evaluated property injection using decorators.
- [inversify-express-utils](https://github.com/inversify/inversify-express-utils) - Some utilities for the development of express application with Express.
- [inversify-restify-utils](https://github.com/inversify/inversify-restify-utils) - Some utilities for the development of express application with Restify.
- [inversify-vanillajs-helpers](https://github.com/inversify/inversify-vanillajs-helpers) - Some helpers for the development of InversifyJS applications with VanillaJS or Babel.
Expand Down
52 changes: 0 additions & 52 deletions wiki/property_injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,55 +79,3 @@ create the instances of the classes in an application.

The problem is that some frameworks take the control over the creation of instances.
For example, React takes control over the creation of instances of a given Component.

We have developed an utility that allows you to inject into a property even when
InversifyJS has not created its instances:

```ts
import getDecorators from "inversify-inject-decorators";
import { Container, injectable } from "inversify";

@injectable()
class PrintService {
// ...
}

let container = new Container();
container.bind<PrintService>("PrintService").to(PrintService);
let { lazyInject } = getDecorators(container);

class Book {

private _author: string;
private _summary: string;

@lazyInject("PrintService")
private _printService: PrintService;

constructor(author: string, summary: string) {
this._author = author;
this._summary = summary;
}

public print() {
this._printService.print(this);
}

}

// Book instance is NOT created by InversifyJS
let book = new Book("Title", "Summary");
book.print();
```

The utility module is called `inversify-inject-decorators`
and provides the following decorators:

- `@lazyInject` for the injection of a property without metadata
- `@lazyInjectNamed` for the injection of a property without named metadata.
- `@lazyInjectTagged` for the injection of a property without tagged metadata.
- `@lazyMultiInject` for multi-injections.

Please visit the module
[project on GitHub](https://github.com/inversify/inversify-inject-decorators)
to learn more.

0 comments on commit 8ddb3f6

Please sign in to comment.