From ee58b26efe4af8e5082c5e3d2896bc59c209187c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Pintos=20L=C3=B3pez?= Date: Tue, 31 Dec 2024 18:49:40 +0100 Subject: [PATCH] feat(inversify-site): add container module API docs --- .../docs/api/container-module.mdx | 83 +++++++++++++++++++ .../inversify-site/docs/api/container.mdx | 13 ++- 2 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 packages/docs/services/inversify-site/docs/api/container-module.mdx diff --git a/packages/docs/services/inversify-site/docs/api/container-module.mdx b/packages/docs/services/inversify-site/docs/api/container-module.mdx new file mode 100644 index 00000000..7b091525 --- /dev/null +++ b/packages/docs/services/inversify-site/docs/api/container-module.mdx @@ -0,0 +1,83 @@ +--- +sidebar_position: 2 +title: Container Module +--- +import containerModuleApiExampleSource from '@inversifyjs/code-examples/generated/examples/containerModuleApiExample.ts.txt'; +import CodeBlock from '@theme/CodeBlock'; + +# ContainerModule + +Container modules can help you to manage the complexity of your 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. + +### bind + +```ts +bind: interfaces.Bind +``` + +Consider [docs](/docs/api/container#bind) as reference. + +### unbind + +``` +unbind: interfaces.Unbind +``` + +Consider [docs](/docs/api/container#unbind) as reference. + +### isBound + +```ts +isBound: interfaces.IsBound +``` + +Consider [docs](/docs/api/container#isbound) as reference. + +### rebind + +```ts +rebind: interfaces.Rebind +``` + +Consider [docs](/docs/api/container#rebind) as reference. + +### unbindAsync + +```ts +unbindAsync: interfaces.UnbindAsync +``` + +Consider [docs](/docs/api/container#unbindasync) as reference. + +### onActivation + +```ts +onActivation: interfaces.Container['onActivation'] +``` + +Consider [docs](/docs/api/container#onactivation) as reference. + +### onDeactivation + +```ts +onDeactivation: interfaces.Container['onDeactivation'] +``` + +Consider [docs](/docs/api/container#ondeactivation) as reference. + +## 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 unloaded from a Container the bindings added by that container will be removed and the [deactivation process](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md) will occur for each of them. Container deactivation and [activation handlers](https://github.com/inversify/InversifyJS/blob/master/wiki/activation_handler.md) will also be removed. +Use the unloadAsync method to unload when there will be an async deactivation handler or async [pre destroy](https://github.com/inversify/InversifyJS/blob/master/wiki/pre_destroy.md) + +{containerModuleApiExampleSource} diff --git a/packages/docs/services/inversify-site/docs/api/container.mdx b/packages/docs/services/inversify-site/docs/api/container.mdx index dcb62044..4b8b7c3d 100644 --- a/packages/docs/services/inversify-site/docs/api/container.mdx +++ b/packages/docs/services/inversify-site/docs/api/container.mdx @@ -30,7 +30,7 @@ import containerApiRebindSource from '@inversifyjs/code-examples/generated/examp import containerApiResolveSource from '@inversifyjs/code-examples/generated/examples/containerApiResolve.ts.txt'; import CodeBlock from '@theme/CodeBlock'; -# The Container API +# 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. @@ -292,7 +292,7 @@ You can use the `isBoundTagged` method to check if there are registered bindings load(...modules: interfaces.ContainerModule[]): void; ``` -Calls the registration method of each module. See [container modules](https://github.com/inversify/InversifyJS/blob/master/wiki/container_modules.md) +Calls the registration method of each module. See [ContainerModule API docs](/docs/api/container-module) ## loadAsync @@ -308,7 +308,7 @@ As per load but for asynchronous registration. rebind(serviceIdentifier: interfaces.ServiceIdentifier): interfaces.BindingToSyntax; ``` -You can use the `rebind` method to replace all the existing bindings for a given `serviceIdentifier`. +Replaces all the existing bindings for a given `serviceIdentifier`. The function returns an instance of `BindingToSyntax` which allows to create the replacement binding. {containerApiRebindSource} @@ -478,8 +478,7 @@ Remove all bindings binded in this container to the service identifier. This wi unbindAsync(serviceIdentifier: interfaces.ServiceIdentifier): Promise; ``` -This is the asynchronous version of unbind. If you know deactivation is asynchronous then this should be used. -If you are not sure then use this method ! +This is the asynchronous version of unbind. If any deactivation realated to this service identifier is asynchronous then this method should be used instead of `container.unbind`. ## unbindAll @@ -503,8 +502,8 @@ This is the asynchronous version of unbindAll. If any of the container's deactiv unload(...modules: interfaces.ContainerModuleBase[]): void; ``` -Removes bindings and handlers added by the modules. This will result in the [deactivation process](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md). -See [container modules](https://github.com/inversify/InversifyJS/blob/master/wiki/container_modules.md) +Removes bindings and handlers added by the modules. This will result in the [deactivation process](https://github.com/inversify/InversifyJS/blob/master/wiki/deactivation_handler.md). +See [ContainerModule API docs](/docs/api/container-module). ## unloadAsync