npm.io
1.0.1 • Published 5 years ago

inversify-extension

Licence
MIT
Version
1.0.1
Deps
2
Size
10 kB
Vulns
0
Weekly
0

InversifyJS Extension

About

InversifyJS Extension is project

Installation

You can get the latest release and the type definitions using npm:

$ npm install inversify inversify-extension reflect-metadata

Examples

AutoNamed factory

The old way for writing named factory:

container.bind<interfaces.Factory<Katana>>("Factory<Katana>")
  .toFactory<Katana>((context: interfaces.Context) => (named: string): Katana => {
    return context.container.getNamed<Katana>("Katana", named);
  });

Now you can write in a more simple way:

import { ContainerExtension } from 'inversify-extension';

const container = new ContainerExtension();

container.bind<interfaces.Factory<Katana>>("Factory<Katana>")
  .toAutoNamedFactory<Katana>("Katana");

The same way for a factory that works with tags:

import { ContainerExtension } from 'inversify-extension';

const container = new ContainerExtension();

container.bind<interfaces.Factory<Katana>>("Factory<Katana>")
  .toAutoTaggedFactory<Katana>("Katana");