You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/essential/plugin.md
+1-27Lines changed: 1 addition & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -155,36 +155,10 @@ We can use the plugin by passing an instance to **Elysia.use**.
155
155
156
156
<Playground:elysia="demo1" />
157
157
158
-
The plugin will inherit all properties of the plugin instance like `state`, `decorate` but **WILL NOT inherit plugin lifecycle** as it's [isolated by default](#scope).
158
+
The plugin will inherit all properties of the plugin instance like `state`, `decorate` but **WILL NOT inherit plugin lifecycle** as it's [isolated by default](#scope) (mentioned in the next section ↓).
159
159
160
160
Elysia will also handle the type inference automatically as well.
161
161
162
-
## Plugin
163
-
164
-
Every Elysia instance can be a plugin.
165
-
166
-
We decouple our logic into a separate Elysia instance and reuse it across multiple instances.
167
-
168
-
To create a plugin, simply define an instance in a separate file:
169
-
```typescript twoslash
170
-
// plugin.ts
171
-
import { Elysia } from'elysia'
172
-
173
-
exportconst plugin =newElysia()
174
-
.get('/plugin', () =>'hi')
175
-
```
176
-
177
-
And then we import the instance into the main file:
178
-
```typescript
179
-
import { Elysia } from'elysia'
180
-
import { plugin } from'./plugin'// [!code ++]
181
-
182
-
const app =newElysia()
183
-
.use(plugin) // [!code ++]
184
-
.listen(3000)
185
-
```
186
-
187
-
188
162
## Scope
189
163
190
164
Elysia lifecycle methods are **encapsulated** to its own instance only.
0 commit comments