Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fluent/di

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluent/di

Fluent - DI component

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
increased by76.92%
Maintainers
1
Weekly downloads
 
Created
Source

Dependency injection

Fluent use reflect-metadata for reflection and you need two conditions for proper functioning:

  • you must add "experimentalDecorators": true to your tsconfig.json file
  • you must add "emitDecoratorMetadata": true to your tsconfig.json file

This component has an identical implementation approach as ASP.NET Core and has a number of inconveniences.

The reflection can not be realized without decorators and therefore it is necessary to use the @Injectable() decorator for all classes to use dependency injection.

Example of usage:

@Injectable()
export class PingService {
}

This decorator only emit metadata and does not process anything.

The service collection is carried out with the help of the ServiceCollection class and it has three main methods that add the right lifetime:

  • addSingleton() - an instance of a service is always the same
  • addScope() - an instance of a service is always the same if its call occurs in one scope
  • addTransient() - the service instance is always unique

Example of usage:

@Main()
export class Startup {
  configureServices(services: ServiceCollection) {
    services.addSingleton(PingService);
  }
}

You can also get an instance of the service in the constructor:

@Injectable()
export class PongService {
  constructor(pingService: PingService) {
  }
}

When calling PongService the instance will receive PingService as constructor argument.

Keywords

FAQs

Package last updated on 03 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc