Skip to content

Commit

Permalink
document service provider shutdown method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jun 19, 2022
1 parent da301e3 commit 42530cf
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion service-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export class MarkdownServiceProvider extends ServiceProvider {
The `register` method binds an implementation of the `MarkdownRenderer` into the container. Please find more details about [the container and bindings](/docs/service-container) in its documentation.



### The Boot Method
The `boot` method is called after all service providers have been registered. Here, you have access to all services in the container. The `boot` method runs asynchronously and can return a promise. Use this method to boot your application services.

Expand All @@ -91,6 +90,29 @@ export class MarkdownServiceProvider extends ServiceProvider {
```


### The Shutdown Method
The `shutdown` method of all registered services providers runs when the Node.js process receives one of the following signals:

- `SIGINT`
- `SIGTERM`

The `shutdown` method is a way to stop services, like database connections. For example, let’s say the markdown renderer needs to properly close a connection. The `shutdown` method is the correct to do that:

```ts
import { ServiceProvider } from '@supercharge/support'
import { MarkdownRenderer } from './markdown-renderer'

export class MarkdownServiceProvider extends ServiceProvider {
/**
* Shutdown application services.
*/
override async shutdown (): Promise<void> {
await this.app().make(MarkdownRenderer).stop()
}
}
```


## Registering Providers
All service providers are registered through the `bootstrap/providers.ts` file. This file must export a `providers` property. The value of this property is an array of service providers. You’ll find a handful of default service providers, for example the route service provider.

Expand Down

0 comments on commit 42530cf

Please sign in to comment.