1
votes

Looking for best practices to implement the following scenario using SystemJS and Type script -

  1. AbstractLogger.d.ts - Should declare (export) module with some classes.
  2. ConsoleLogger.ts - Should "implement" AbstractLogger.
  3. Consumer.ts - Should reference AbstractLogger class, and use it.

Everything compiles, but where should I Inject the ConsoleLogger as the current AbstractLogger implementation? In server side code it's easy to achieve using simple DI, How it should be done here?

Tried to use the System.config (map: ...) with no luck. Is this the correct pattern, or i'm missing something here?

Thanks!

2

2 Answers

0
votes

In server side code it's easy to achieve using simple DI, How it should be done here

The ES6 module loader is not a DI. It can be thought of a script tag creator (file ordering) + revealing module pattern wrapper (prevent global pollution) if that helps.

For DI you need a DI library. E.g. its easy to use Inversify with some module loader (including systemjs) : Typescript IOC in case of node

0
votes

A DI library is required- a module loader is not a dependency injection container.

Give the Aurelia dependency-injection container a try. It's a stand-alone library with no dependencies, works in the browser and in node with has support for both TypeScript and JavaScript.