Skip to main content

Writing plugins

The functionality of Basica's AppBuilder can be extended to provide reusable builder functions.

Lifecycle plugin

plugin.ts
import { AppRequiredDeps, LifecycleManagerBuilder } from "@basica/core";

class LifecyclePlugin<S extends AppRequiredDeps> {
constructor(readonly lifecycle: LifecycleManagerBuilder<S>) {}

newMethod() {
//...
}
}

export const lifecyclePlugin = <S extends AppRequiredDeps>(
lifecycle: LifecycleManagerBuilder<S>
) => new LifecyclePlugin(lifecycle);
index.ts
// ...

const app = new AppBuilder(container)
.configureLifecycle((b) =>
b.with(lifecyclePlugin, (b) => b.newMethod())
)
.build();

// ...