Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply copilot suggestions #273

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 28 additions & 27 deletions packages/docs/services/inversify-site/docs/api/binding-syntax.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import bindingWhenSyntaxApiWhenSource from '@inversifyjs/code-examples/generated
import CodeBlock from '@theme/CodeBlock';

# Binding Syntax
Binding syntax is provided as a fluent interface provided as the result of using the [container API](/docs/api/container#bind) or the [container module API](/docs/api/container-module#bind)

Binding syntax is provided as a fluent interface resulting from using the [container API](/docs/api/container#bind) or the [container module API](/docs/api/container-module#bind).

## BindingToSyntax

Expand All @@ -33,15 +34,15 @@ Represents a service binding given a service identifier.
const bindingToSyntax = container.bind('service-id');
```

Further docs refers to this service identifier as the "given service identifier".
Further documentation refers to this service identifier as the "given service identifier".

### to

```ts
to(constructor: interfaces.Newable<T>): interfaces.BindingInWhenOnSyntax<T>;
```

Binds a class instantiation to the given service binding. Whenever the service is resolved, the class constructor will be invoked in order to build the resolved value.
Binds a class instantiation to the given service binding. Whenever the service is resolved, the class constructor will be invoked to build the resolved value.

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

Expand Down Expand Up @@ -71,7 +72,7 @@ Binds a value in singleton scope to the given service identifier.
toDynamicValue(func: interfaces.DynamicValue<T>): interfaces.BindingInWhenOnSyntax<T>;
```

Binds a function to the given service id. Whenever the service is resolved, the function passed will be invoked in order to build the resolved value.
Binds a function to the given service id. Whenever the service is resolved, the function passed will be invoked to build the resolved value.

:::info

Expand Down Expand Up @@ -115,7 +116,7 @@ An alias of `BindingToSyntax.toConstantValue` restricted to functions.
toAutoFactory<T2>(serviceIdentifier: interfaces.ServiceIdentifier<T2>): interfaces.BindingWhenOnSyntax<T>;
```

Binds a factory of services asociated a target service identifier to the given service identifier.
Binds a factory of services associated with a target service identifier to the given service identifier.

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

Expand All @@ -125,7 +126,7 @@ Binds a factory of services asociated a target service identifier to the given s
toAutoNamedFactory<T2>(serviceIdentifier: interfaces.ServiceIdentifier<T2>): BindingWhenOnSyntax<T>;
```

Binds a factory of services asociated a target service identifier and a name to the given service identifier.
Binds a factory of services associated with a target service identifier and a name to the given service identifier.

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

Expand All @@ -135,7 +136,7 @@ Binds a factory of services asociated a target service identifier and a name to
toProvider<T2>(provider: interfaces.ProviderCreator<T2>): interfaces.BindingWhenOnSyntax<T>;
```

Binds a provider of services asociated a target service identifier to the given service identifier. A provider is just an asyncronous factory.
Binds a provider of services associated with a target service identifier to the given service identifier. A provider is just an asynchronous factory.

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

Expand All @@ -157,31 +158,31 @@ interface BindingInSyntax<T> {
}
```

Represents a service binding given a service identifier and a service resolution such as a contructor, a factory or a provider.
Represents a service binding given a service identifier and a service resolution such as a constructor, a factory, or a provider.

### inSingletonScope

```ts
inSingletonScope(): BindingWhenOnSyntax<T>;
```

Sets the binding scope to singleton. Consider [docs](/docs/fundamentals/binding#singleton) as reference.
Sets the binding scope to singleton. Refer to the [docs](/docs/fundamentals/binding#singleton) for more information.

### inTransientScope

```ts
inTransientScope(): BindingWhenOnSyntax<T>;
```

Sets the binding scope to transient. Consider [docs](/docs/fundamentals/binding#transient) as reference.
Sets the binding scope to transient. Refer to the [docs](/docs/fundamentals/binding#transient) for more information.

### inRequestScope

```ts
inRequestScope(): BindingWhenOnSyntax<T>;
```

Sets the binding scope to request. Consider [docs](/docs/fundamentals/binding#request) as reference.
Sets the binding scope to request. Refer to the [docs](/docs/fundamentals/binding#request) for more information.

## BindingOnSyntax

Expand Down Expand Up @@ -209,7 +210,7 @@ Sets a binding activation handler. The activation handler is invoked after a dep
onDeactivation(fn: (injectable: T) => void | Promise<void>): BindingWhenSyntax<T>;
```

Sets a binding deactivation handler on a singleton scope binding. The deactivation handler is caled when the binding is unbound from a container.
Sets a binding deactivation handler on a singleton scope binding. The deactivation handler is called when the binding is unbound from a container.

## BindingWhenSyntax

Expand All @@ -235,7 +236,7 @@ In the previous example, a custom constraint is implemented to use the binding i

### whenTargetNamed

Constraints the binding to be used if and only if the target name is a certain one.
Constrains the binding to be used if and only if the target name is a certain one.

```ts
whenTargetNamed(name: string | number | symbol): BindingOnSyntax<T>;
Expand All @@ -247,107 +248,107 @@ whenTargetNamed(name: string | number | symbol): BindingOnSyntax<T>;
whenTargetIsDefault(): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if the target has no name nor tags.
Constrains the binding to be used if and only if the target has no name nor tags.

### whenTargetTagged

```ts
whenTargetTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if the target tag is a certain one.
Constrains the binding to be used if and only if the target tag is a certain one.

### whenInjectedInto

```ts
whenInjectedInto(parent: NewableFunction | string): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if the parent target service identifier is a certain one.
Constrains the binding to be used if and only if the parent target service identifier is a certain one.

### whenParentNamed

```ts
whenParentNamed(name: string | number | symbol): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if the parent target name is a certain one.
Constrains the binding to be used if and only if the parent target name is a certain one.

### whenParentTagged

```ts
whenParentTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if the parent target tag is a certain one.
Constrains the binding to be used if and only if the parent target tag is a certain one.

### whenAnyAncestorIs

```ts
whenAnyAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if any ancestor target service identifier is a certain one.
Constrains the binding to be used if and only if any ancestor target service identifier is a certain one.

### whenNoAncestorIs

```ts
whenNoAncestorIs(ancestor: NewableFunction | string): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if no ancestor target service identifier is a certain one.
Constrains the binding to be used if and only if no ancestor target service identifier is a certain one.

### whenAnyAncestorNamed

```ts
whenAnyAncestorNamed(name: string | number | symbol): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if any ancestor target name is a certain one.
Constrains the binding to be used if and only if any ancestor target name is a certain one.

### whenAnyAncestorTagged

```ts
whenAnyAncestorTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if any ancestor target tag is a certain one.
Constrains the binding to be used if and only if any ancestor target tag is a certain one.

### whenNoAncestorNamed

```ts
whenNoAncestorNamed(name: string | number | symbol): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if no ancestor target name is a certain one.
Constrains the binding to be used if and only if no ancestor target name is a certain one.

### whenNoAncestorTagged

```ts
whenNoAncestorTagged(tag: string | number | symbol, value: unknown): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if no ancestor target tag is a certain one.
Constrains the binding to be used if and only if no ancestor target tag is a certain one.

### whenAnyAncestorMatches

```ts
whenAnyAncestorMatches(constraint: (request: Request) => boolean): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if any ancestor matches a certain constraint.
Constrains the binding to be used if and only if any ancestor matches a certain constraint.

### whenNoAncestorMatches

```ts
whenNoAncestorMatches(constraint: (request: Request) => boolean): BindingOnSyntax<T>;
```

Constraints the binding to be used if and only if no ancestor matches a certain constraint.
Constrains the binding to be used if and only if no ancestor matches a certain constraint.

## BindingWhenOnSyntax

The union of [BindingWhenSyntax](#bindingwhensyntax) and [BindingOnSyntax](#bindingonsyntax)
The union of [BindingWhenSyntax](#bindingwhensyntax) and [BindingOnSyntax](#bindingonsyntax).

```ts
export interface BindingWhenOnSyntax<T>
Expand Down
23 changes: 11 additions & 12 deletions packages/docs/services/inversify-site/docs/api/container-module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,76 @@ import CodeBlock from '@theme/CodeBlock';

# ContainerModule

Container modules can help you to manage the complexity of your bindings in large applications.
Container modules help manage the complexity of bindings in large applications.

## Constructor

```ts
constructor(registry: interfaces.ContainerModuleCallBack)
```

The constructor argument for `ContainerModule` is a registration callback with function parameters to manage bindings in the scope of the container module.
The constructor argument for `ContainerModule` is a registration callback with function parameters to manage bindings within the scope of the container module.

### bind

```ts
bind: interfaces.Bind
```

Consider [docs](/docs/api/container#bind) as reference.
Refer to the [docs](/docs/api/container#bind) for more information.

### unbind

```
unbind: interfaces.Unbind
```

Consider [docs](/docs/api/container#unbind) as reference.
Refer to the [docs](/docs/api/container#unbind) for more information.

### isBound

```ts
isBound: interfaces.IsBound
```

Consider [docs](/docs/api/container#isbound) as reference.
Refer to the [docs](/docs/api/container#isbound) for more information.

### rebind

```ts
rebind: interfaces.Rebind
```

Consider [docs](/docs/api/container#rebind) as reference.
Refer to the [docs](/docs/api/container#rebind) for more information.

### unbindAsync

```ts
unbindAsync: interfaces.UnbindAsync
```

Consider [docs](/docs/api/container#unbindasync) as reference.
Refer to the [docs](/docs/api/container#unbindasync) for more information.

### onActivation

```ts
onActivation: interfaces.Container['onActivation']
```

Consider [docs](/docs/api/container#onactivation) as reference.
Refer to the [docs](/docs/api/container#onactivation) for more information.

### onDeactivation

```ts
onDeactivation: interfaces.Container['onDeactivation']
```

Consider [docs](/docs/api/container#ondeactivation) as reference.
Refer to the [docs](/docs/api/container#ondeactivation) for more information.

## Example: binding services through ContainerModule API

When a container module is loaded into a Container the registration callback is invoked. This is the opportunity for the container module to register bindings and handlers. Use the Container load method for ContainerModule instances and the Container loadAsync method for AsyncContainerModule instances.
When a container module is loaded into a Container, the registration callback is invoked. This is the opportunity for the container module to register bindings and handlers. Use the Container `load` method for `ContainerModule` instances and the Container `loadAsync` method for `AsyncContainerModule` instances.

When a container module is unloaded from a Container the bindings added by that container will be removed and the [deactivation process](/docs/fundamentals/lifecycle/deactivation) will occur for each of them. Container deactivation and [activation handlers](/docs/fundamentals/lifecycle/activation) will also be removed.
Use the unloadAsync method to unload when there will be an async deactivation handler or async [preDestroy](/docs/api/decorator#predestroy)
When a container module is unloaded from a Container, the bindings added by that container will be removed, and the [deactivation process](/docs/fundamentals/lifecycle/deactivation) will occur for each of them. Container deactivation and [activation handlers](/docs/fundamentals/lifecycle/activation) will also be removed. Use the `unloadAsync` method to unload when there will be an async deactivation handler or async [preDestroy](/docs/api/decorator#predestroy).

<CodeBlock language="ts">{containerModuleApiExampleSource}</CodeBlock>
18 changes: 8 additions & 10 deletions packages/docs/services/inversify-site/docs/api/container.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ import CodeBlock from '@theme/CodeBlock';

# Container

The InversifyJS container is where dependencies are first configured through bind and, possibly later, reconfigured and removed. The container can be worked on directly in this regard or container modules can be utilized.
You can query the configuration and resolve configured dependencies with resolved and the 'get' methods.
The InversifyJS container is where dependencies are first configured through binding and, possibly later, reconfigured and removed. The container can be worked on directly in this regard or container modules can be utilized.
You can query the configuration and resolve configured dependencies with the `get` methods.
You can react to resolutions with container activation handlers and unbinding with container deactivation handlers.
You can create container hierarchies where container ascendants can supply the dependencies for descendants.
For testing, state can be saved as a snapshot on a stack and later restored.
For advanced control you can apply middleware to intercept the resolution request and the resolved dependency.
For advanced control, you can apply middleware to intercept the resolution request and the resolved dependency.
You can even provide your own annotation solution.


## Container Options
Container options can be passed to the Container constructor and defaults will be provided if you do not or if you do but omit an option.

Container options can be passed to the Container constructor, and defaults will be provided if you do not or if you do but omit an option.
Options can be changed after construction and will be shared by child containers created from the Container if you do not provide options for them.

### defaultScope

The default scope is `transient` when binding to/toSelf/toDynamicValue/toService.
Other bindings can only be bound in `singleton` scope.

You can use container options to change the default scope for the bindings that default to `transient` at application level:
You can use container options to change the default scope for the bindings that default to `transient` at the application level:

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

Expand All @@ -67,9 +67,7 @@ Manually defined bindings will take precedence:

### skipBaseClassChecks

You can use this to skip checking base classes for the @injectable property, which is
especially useful if any of your @injectable classes extend classes that you don't control
(third party classes). By default, this value is `false`.
You can use this to skip checking base classes for the `@injectable` property, which is especially useful if any of your `@injectable` classes extend classes that you don't control (third-party classes). By default, this value is `false`.

```ts
const container = new Container({ skipBaseClassChecks: true });
Expand Down Expand Up @@ -259,7 +257,7 @@ You can use the `isBound` method to check if there are registered bindings for a
## isCurrentBound

```ts
isCurrentBound(serviceIdentifier: interfaces.ServiceIdentifier\<unknown>): boolean
isCurrentBound(serviceIdentifier: interfaces.ServiceIdentifier<unknown>): boolean;
```

You can use the `isCurrentBound` method to check if there are registered bindings for a given service identifier only in the current container.
Expand Down
Loading
Loading