1.0.4 • Published 6 months ago

@uxland/ioc v1.0.4

Weekly downloads
-
License
BSD-4-Clause
Repository
github
Last release
6 months ago

UXL IOC npm version

Build StatusStatementsBranchesFunctionsLines
BuildStatusStatementsBranchesFunctionsLines

Installation

npm i @uxland/ioc

Usage

Register constructor singleton to iocContainer

Registers a constructor singleton to the InversionOfControl container. Each time a reference of the constructor or abstract class is provided with inversify, the container will provide with its singleton pair.

@provideSingleton()
class IOCAdapter {
  method(): void {
    console.log("Calling `method` from `IOCAdapter`");
  }
}

class Adapter {
  constructor(@inject(IOCAdapter) protected adapter: IOCAdapter) {
    this.adapter.method(); // => 'Calling `method` from `IOCAdapter`'
  }
}

Set Mediator resolver

This method overrides the mediator default resolver to use our own container.

const container: Container = new Container();
setMediatorResolver(container);