Skip to content

Commit

Permalink
feat(inversify-site): update next decorator api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
notaphplover committed Jan 19, 2025
1 parent 2ad5251 commit 2766b52
Showing 1 changed file with 10 additions and 40 deletions.
50 changes: 10 additions & 40 deletions packages/docs/services/inversify-site/docs/api/decorator.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,7 +30,6 @@ Whenever class-emitted metadata is expected.
Consider the following sample code:

```ts
import 'reflect-metadata';
import { injectable } from 'inversify';

@injectable()
Expand All @@ -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';
Expand All @@ -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';
}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -140,33 +137,6 @@ Decorator used to establish a relation between a constructor argument or a class

<CodeBlock language="ts">{decoratorApiTaggedSource}</CodeBlock>

## 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>("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.
Expand Down

0 comments on commit 2766b52

Please sign in to comment.