feat: implement Dynamic Modules support (sync and async)

Allows modules to be configured at runtime via static methods returning DynamicModule objects, similar to NestJS forRoot/register patterns.
This commit is contained in:
M1000fr
2026-01-11 17:18:15 +01:00
parent 7452f21450
commit deb9e704fb
4 changed files with 167 additions and 26 deletions

View File

@@ -1,4 +1,5 @@
import { Container } from "../container/Container";
import type { DynamicModule } from "../container/types";
import type { Constructor } from "../types";
import { AlveoApplication } from "./AlveoApplication";
@@ -13,11 +14,13 @@ export class AlveoFactoryStatic {
* @param rootModule The root module of the application.
* @returns A promise that resolves to an AlveoApplication instance.
*/
public async create(rootModule: Constructor): Promise<AlveoApplication> {
public async create(
rootModule: Constructor | DynamicModule,
): Promise<AlveoApplication> {
const container = new Container();
// 1. Register the module tree starting from the root module
container.registerRootModule(rootModule);
await container.registerRootModule(rootModule);
// 2. Resolve all providers (this builds the graph and instantiates singletons)
await container.resolveAll();