Socket
Socket
Sign inDemoInstall

@fluent/di

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @fluent/di

Fluent - DI component


Version published
Weekly downloads
12
increased by33.33%
Maintainers
1
Install size
311 kB
Created
Weekly downloads
 

Readme

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

Last updated on 03 Feb 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc