0.10.0 • Published 4 years ago

typedi v0.10.0

Weekly downloads
77,307
License
MIT
Repository
github
Last release
4 years ago

TypeDI

Build Status codecov npm version Dependency Status

TypeDI is a dependency injection tool for TypeScript and JavaScript. With it you can build well-structured and easily testable applications in Node or in the browser.

Main features includes:

  • property based injection
  • constructor based injection
  • singleton and transient services
  • support for multiple DI containers

Installation

Note: This installation guide is for usage with TypeScript, if you wish to use TypeDI without Typescript please read the documentation about how get started.

To start using TypeDI install the required packages via NPM:

npm install typedi reflect-metadata

Import the reflect-metadata package at the first line of your application:

import 'reflect-metadata';

// Your other imports and initialization code
// comes here after you imported the reflect-metadata package!

As a last step, you need to enable emitting decorator metadata in your Typescript config. Add these two lines to your tsconfig.json file under the compilerOptions key:

"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Now you are ready to use TypeDI with Typescript!

Basic Usage

import { Container, Service } from 'typedi';

@Service()
class ExampleInjectedService {
  printMessage() {
    console.log('I am alive!');
  }
}

@Service()
class ExampleService {
  constructor(
    // because we annotated ExampleInjectedService with the @Service()
    // decorator TypeDI will automatically inject an instance of
    // ExampleInjectedService here when the ExampleService class is requested
    // from TypeDI.
    private injectedService: ExampleInjectedService
  ) {}
}

const serviceInstance = Container.get(ExampleService);
// we request an instance of ExampleService from TypeDI

serviceInstance.injectedService.printMessage();
// logs "I am alive!" to the console

Documentation

The detailed usage guide and API documentation for the project can be found:

Contributing

Please read our contributing guidelines to get started.

@overtheairbrew/homebrew-plugin@overtheairbrew/tilt-bridgen8n-nodes-telepilotalerts-controllerdotclub-admin-web-backendmoonpay-apiunleashed-apiapi-parceiros@instaserv/web-aws@etherspot/relay@dddl/eda@dddl/eda-inmemory@dddl/usecasemqtt-decorators@worksolutons/utils@yokita/stp-commonjustt-tyx-newapfm-rules-engine@lartplus/cli@purepack-common/cli@kaviar/corexendit-cypress-frameworkpet-modelsproject-estimation-tool-modelsexpress-typescript-templategeneric-type-guard-climiddleware-service-validationneutronpay-wallet-common@goboomtown/sdk-falcan-testneo-apisdfsdfdwebexapiscurated-pull-out-sources-ph@fortification/corejs-physics-2djs-physics-2d-threaded@ethanlibs/corelite-typedioffline-quest-verificationsavegao-microframework-winstonhempi@quantform/editor@quantform/expressf800-core@chttrbx/jwttypescript-databasesequelize-typescript-clityx@everything-registry/sub-chunk-2994deestjzan-proxyceostasci-coret-configuratortest-ic-wallet-middleware-commontest-ic-wallet-middleware-hpltest-ic-wallet-middleware-icrcwebpack4-vue-tswebstar-appium-dashboardwildspiderwhatsapp-viewerws-routingsafetrack-loggersafetrack-subscription-balanceserverless-sub-routingscoreboard-libtemplate-processor-v2stathis-coresportywide-webspeedgoosespectrum-botsteadymdsdk-ixsdk-ts-testrouting-controllers-wrapperthe_power_clivespervesper-jbpitts@sasyesp03/elsa-workflows-studio-ulixemrn-lrpctest-ic-wallet-middleware1-hpltest-ic-package-commonminecraft-proxymiddleware-loggergraphstackikariillolaborehydra-e2e-testsirpayix-sdk-tslite-ts-apilite-ts-apiexlite-ts-typedilhisp-business-prismalhisp-business-prisma-devlhisp-business-tslhisp-business-ts-devlhisp-business-ts-drizzlelhisp-getdbconfiglib-base-api-koamicroframe-ts
0.10.0

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago

0.8.0

7 years ago

0.7.3

7 years ago

0.7.2

7 years ago

0.7.1

7 years ago

0.7.0

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.2

8 years ago

0.5.1

8 years ago

0.5.0

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.0

9 years ago

0.2.0

9 years ago

0.1.0

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago