Dwex Logo

Fundamentals

Advanced dependency injection and module concepts

Advanced Concepts

Deep dive into the powerful dependency injection system and advanced module features that make Dwex applications scalable and maintainable.

Dependency Injection

Dwex provides a sophisticated DI container that manages the lifecycle of your application components. Learn how to leverage custom providers, injection scopes, and advanced patterns.

Module System

Go beyond basic module organization to understand dynamic modules, lazy loading, circular dependencies, and module references.

Key Topics

Dependency Injection - Understanding the DI container and how dependencies are resolved.

Custom Providers - Create custom provider configurations for advanced use cases.

Injection Scopes - Control the lifecycle of your providers with singleton, request, and transient scopes.

Dynamic Modules - Build configurable, reusable modules that can be customized at runtime.

Circular Dependencies - Handle and resolve circular dependencies between modules.

Module Reference - Access the DI container programmatically to resolve dependencies dynamically.

Testing - Write testable code with dependency injection and learn testing strategies.

Example: Custom Provider

@Module({
	providers: [
		{
			provide: "CONFIG",
			useFactory: () => ({
				apiUrl: Bun.env.API_URL,
				timeout: Number(Bun.env.TIMEOUT) || 5000,
			}),
		},
		{
			provide: ApiService,
			useClass: Bun.env.NODE_ENV === "production"
				? ProductionApiService
				: DevelopmentApiService,
		},
	],
})
export class AppModule {}

Learn More