You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

inversify-binding-decorators

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inversify-binding-decorators

An utility that allows developers to declare InversifyJS bindings using ES2016 decorators

4.0.0
latest
Source
npmnpm
Version published
Weekly downloads
150K
-19.3%
Maintainers
1
Weekly downloads
 
Created

What is inversify-binding-decorators?

The inversify-binding-decorators package provides decorators for InversifyJS, a powerful and flexible inversion of control (IoC) container for JavaScript and TypeScript applications. It simplifies the process of binding classes and interfaces to the IoC container using decorators, making the code more readable and maintainable.

What are inversify-binding-decorators's main functionalities?

Automatic Binding

The automatic binding feature allows you to use the @provide decorator to automatically bind a class to the InversifyJS container. This eliminates the need for manual binding in the container configuration, making the code cleaner and easier to manage.

```typescript
import { Container } from 'inversify';
import { provide } from 'inversify-binding-decorators';

@provide(Foo)
class Foo {
  public sayHello() {
    return 'Hello from Foo!';
  }
}

const container = new Container();
const foo = container.get(Foo);
console.log(foo.sayHello()); // Output: Hello from Foo!
```

Named Bindings

Named bindings allow you to bind multiple implementations of the same interface or class under different names. The @provideNamed decorator is used to specify the name of the binding, and the @named decorator is used to inject the specific named binding into a class.

```typescript
import { Container, inject } from 'inversify';
import { provideNamed } from 'inversify-binding-decorators';

@provideNamed('MyService', 'ServiceA')
class ServiceA {
  public getName() {
    return 'ServiceA';
  }
}

@provideNamed('MyService', 'ServiceB')
class ServiceB {
  public getName() {
    return 'ServiceB';
  }
}

class Consumer {
  constructor(@inject('MyService') @named('ServiceA') private service: ServiceA) {}

  public useService() {
    return this.service.getName();
  }
}

const container = new Container();
const consumer = container.get(Consumer);
console.log(consumer.useService()); // Output: ServiceA
```

Other packages similar to inversify-binding-decorators

Keywords

InversifyJS

FAQs

Package last updated on 19 Apr 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.