From 8ddb3f637fad1b1c6b896c6faad5cb58dd054e55 Mon Sep 17 00:00:00 2001 From: notaphplover Date: Sat, 14 Dec 2024 19:40:17 +0100 Subject: [PATCH] docs: remove inversify-inject-decorators references (#1681) --- wiki/circular_dependencies.md | 6 ++-- wiki/classes_as_id.md | 10 ++----- wiki/ecosystem.md | 1 - wiki/property_injection.md | 52 ----------------------------------- 4 files changed, 5 insertions(+), 64 deletions(-) diff --git a/wiki/circular_dependencies.md b/wiki/circular_dependencies.md index 6dadf860e..0a6226592 100644 --- a/wiki/circular_dependencies.md +++ b/wiki/circular_dependencies.md @@ -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: diff --git a/wiki/classes_as_id.md b/wiki/classes_as_id.md index f95bc753e..25e5a36b2 100644 --- a/wiki/classes_as_id.md +++ b/wiki/classes_as_id.md @@ -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 { @@ -82,7 +80,7 @@ class Dom { @injectable() class DomUi { - @lazyInject(Dom) public dom: Dom; + @inject(Dom) public dom: Dom; } @injectable() @@ -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"), @@ -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"; } diff --git a/wiki/ecosystem.md b/wiki/ecosystem.md index 3bed85d8a..7eed8576d 100644 --- a/wiki/ecosystem.md +++ b/wiki/ecosystem.md @@ -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. diff --git a/wiki/property_injection.md b/wiki/property_injection.md index f9bee5ed5..3791813c1 100644 --- a/wiki/property_injection.md +++ b/wiki/property_injection.md @@ -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").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.