Learn how to create and use extensions to extend Resolid Framework functionality
Extensions are the primary way to add functionality to a Resolid application. They can register services, define bootstrap logic, and integrate with the application lifecycle.
Bootstrap functions from all extensions execute in parallel when app.run() is called:
const app = await createApp({ name: 'MyApp', extensions: [ { name: 'extension-a', bootstrap: async () => { await new Promise(resolve => setTimeout(resolve, 100)); console.log('A initialized'); }, }, { name: 'extension-b', bootstrap: async () => { await new Promise(resolve => setTimeout(resolve, 50)); console.log('B initialized'); }, }, ],});await app.run();// Output order may vary:// B initialized// A initialized
Since bootstrap functions run in parallel, be careful about dependencies between extensions. If extension B depends on extension A being initialized, coordinate using events or ensure proper ordering.
When your extension needs configuration, wrap it in a function that returns an ExtensionCreator. This provides type-safe configuration and access to the AppContext.
Name extensions clearly
Use descriptive, unique names for extensions. These names are useful for debugging and understanding the application structure.
Implement cleanup in providers
If your providers allocate resources (connections, file handles, etc.), implement a dispose() method that will be automatically called when the app shuts down.
Use events for inter-extension communication
Rather than directly coupling extensions, use the event emitter available in AppContext to communicate between extensions.