Writing plugins
The functionality of Basica's AppBuilder can be extended to provide reusable builder functions.
Lifecycle plugin
- Classes
- Object Factory
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);
sampleService.ts
import { AppRequiredDeps, LifecycleManagerBuilder } from "@basica/core";
export const lifecyclePlugin = <S extends AppRequiredDeps>(
lifecycle: LifecycleManagerBuilder<S>
) => ({
newMethod: () => {
//...
}
});
index.ts
// ...
const app = new AppBuilder(container)
.configureLifecycle((b) =>
b.with(lifecyclePlugin, (b) => b.newMethod())
)
.build();
// ...