How to use the @tsed/di.Module function in @tsed/di

To help you get started, we’ve selected a few @tsed/di examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / packages / seq / src / SeqModule.ts View on Github external
import {AfterRoutesInit} from "@tsed/common";
import {Constant, Module} from "@tsed/di";
import {$log} from "ts-log-debug";
import {ISeqSettings} from "./interfaces/ISeqSettings";

@Module()
export class SeqModule implements AfterRoutesInit {
  @Constant("seq", {
    url: "http://localhost:5341"
  })
  private config: ISeqSettings;

  $afterRoutesInit() {
    $log.appenders.set("seq", {
      type: "seq",
      levels: ["info", "debug", "trace", "fatal", "error", "warn"],
      url: this.config.url,
      apiKey: this.config.apiKey
    });
  }
}
github TypedProject / ts-express-decorators / packages / common / src / mvc / MvcModule.ts View on Github external
import {InjectorService, Module, ProviderType} from "@tsed/di";
import {ConverterModule} from "../converters/ConverterModule";
import {JsonSchemesService} from "../jsonschema";
import {ControllerBuilder} from "./builders/ControllerBuilder";
import {ControllerProvider} from "./models/ControllerProvider";
import {ParseService} from "./services/ParseService";
import {RouteService} from "./services/RouteService";
import {ValidationService} from "./services/ValidationService";

@Module({
  imports: [InjectorService, ConverterModule, ParseService, ValidationService, JsonSchemesService, RouteService]
})
export class MvcModule {
  constructor(injector: InjectorService) {
    const routers = injector
      .getProviders(ProviderType.CONTROLLER)
      .map(provider => {
        if (!provider.hasParent()) {
          return new ControllerBuilder(provider as ControllerProvider).build(injector);
        }
      })
      .filter(Boolean);

    return {routers};
  }
}