Skip to content

Quick start

Aleksandr Melnik edited this page Oct 18, 2024 · 3 revisions

Quick Start

Step 1: Define Your Modules and Providers

Create a module and a provider using decorators.

import { NsModule, Injectable, Inject } from '@nexus-ioc/core';

@Injectable()
class DependencyService {
  public readonly name = 'World';
}

@Injectable()
export class AppService {
  constructor(
    @Inject(DependencyService)
    private readonly dependencyService: DependencyService,
  ) {
  }

  getHello(): string {
    return `Hello ${this.dependencyService.name}!`;
  }
}

@NsModule({
  providers: [AppService, DependencyService],
})
export class AppModule {}

Step 2: Create an Application

Create and bootstrap your application.

import { NexusApplicationsServer } from '@nexus-ioc/core/dist/server';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NexusApplicationsServer.create(AppModule)
    .bootstrap();
  
  const appService = app.get<AppService>(AppService);
  
  console.log(appService.getHello());
}

bootstrap();
Clone this wiki locally