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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user