From 2766b5296f4b1c82debcfa4ab16285714a04c746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Pintos=20L=C3=B3pez?= Date: Sun, 19 Jan 2025 12:00:36 +0100 Subject: [PATCH] feat(inversify-site): update next decorator api docs --- .../inversify-site/docs/api/decorator.mdx | 50 ++++--------------- 1 file changed, 10 insertions(+), 40 deletions(-) diff --git a/packages/docs/services/inversify-site/docs/api/decorator.mdx b/packages/docs/services/inversify-site/docs/api/decorator.mdx index 9eeefe7..241c25b 100644 --- a/packages/docs/services/inversify-site/docs/api/decorator.mdx +++ b/packages/docs/services/inversify-site/docs/api/decorator.mdx @@ -2,15 +2,15 @@ sidebar_position: 4 title: Decorator --- -import decoratorApiInjectConstructorArgumentSource from '@inversifyjs/code-examples/generated/examples/decoratorApiInjectConstructorArgument.ts.txt'; -import decoratorApiInjectPropertySource from '@inversifyjs/code-examples/generated/examples/decoratorApiInjectProperty.ts.txt'; -import decoratorApiMultiInjectPropertySource from '@inversifyjs/code-examples/generated/examples/decoratorApiMultiInjectProperty.ts.txt'; -import decoratorApiNamedSource from '@inversifyjs/code-examples/generated/examples/decoratorApiNamed.ts.txt'; -import decoratorApiOptionalSource from '@inversifyjs/code-examples/generated/examples/decoratorApiOptional.ts.txt'; -import decoratorApiPostConstructSource from '@inversifyjs/code-examples/generated/examples/decoratorApiPostConstruct.ts.txt'; -import decoratorApiPreDestroySource from '@inversifyjs/code-examples/generated/examples/decoratorApiPreDestroy.ts.txt'; -import decoratorApiTaggedSource from '@inversifyjs/code-examples/generated/examples/decoratorApiTagged.ts.txt'; -import decoratorApiUnmanagedSource from '@inversifyjs/code-examples/generated/examples/decoratorApiUnmanaged.ts.txt'; +import decoratorApiInjectConstructorArgumentSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiInjectConstructorArgument.ts.txt'; +import decoratorApiInjectPropertySource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiInjectProperty.ts.txt'; +import decoratorApiMultiInjectPropertySource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiMultiInjectProperty.ts.txt'; +import decoratorApiNamedSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiNamed.ts.txt'; +import decoratorApiOptionalSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiOptional.ts.txt'; +import decoratorApiPostConstructSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiPostConstruct.ts.txt'; +import decoratorApiPreDestroySource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiPreDestroy.ts.txt'; +import decoratorApiTaggedSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiTagged.ts.txt'; +import decoratorApiUnmanagedSource from '@inversifyjs/code-examples/generated/examples/v7/decoratorApiUnmanaged.ts.txt'; import CodeBlock from '@theme/CodeBlock'; # Decorators @@ -30,7 +30,6 @@ Whenever class-emitted metadata is expected. Consider the following sample code: ```ts -import 'reflect-metadata'; import { injectable } from 'inversify'; @injectable() @@ -48,7 +47,6 @@ A CommonJS transpilation with the [emitDecoratorMetadata](https://www.typescript ```js Object.defineProperty(exports, "__esModule", { value: true }); -require("reflect-metadata"); const inversify_1 = require("inversify"); let B = class B { foo = 'foo'; @@ -72,7 +70,6 @@ TypeScript emits class metadata if and only if there are any class decorators ap ```js Object.defineProperty(exports, "__esModule", { value: true }); -require("reflect-metadata"); class B { foo = 'foo'; } @@ -104,7 +101,7 @@ When resolving an instance of the class, the target constructor argument or prop Decorator used to establish a relation between a constructor argument or a class property and a service ID. -When resolving an instance of the class, the target constructor argument or property will be resolved in the same way [container.getAll](/docs/api/container#getall) behaves with the `enforceBindingConstraints` flag enabled. +When resolving an instance of the class, the target constructor argument or property will be resolved in the same way [container.getAll](/docs/api/container#getall) behaves. ### Example: decorating a property @@ -140,33 +137,6 @@ Decorator used to establish a relation between a constructor argument or a class {decoratorApiTaggedSource} -## targetName - -Decorator used to establish a relation between a constructor argument or a class property name at design time. - -Bundlers might minify code, altering class property names. This decorator keeps track of the original name. - -This property is kept in the `name` property of the `target` request in a binding constraint. - -```ts -@injectable() -class Ninja implements Ninja { - public katana: Weapon; - public shuriken: Weapon; - constructor( - @inject("Weapon") @targetName("katana") katana: Weapon, - @inject("Weapon") @targetName("shuriken") shuriken: Weapon - ) { - this.katana = katana; - this.shuriken = shuriken; - } -} - -container.bind("Weapon").to(Katana).when((request: interfaces.Request) => { - return request.target.name.equals("katana"); -}); -``` - ## unmanaged Decorator used to establish that Inversify should not inject the target constructor argument or property whatsoever.