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

cheap-di

Package Overview
Dependencies
Maintainers
1
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap-di - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

dist/interfaces/registered-type.d.ts

10

dist/container.d.ts
import { Constructor } from "./interfaces/constructor";
import { ConstructorParams } from "./interfaces/constructor-params";
import { RegisteredInstanceType } from "./interfaces/registered-instance-type";
import { RegisteredType } from "./interfaces/registered-type";
declare const container: {
registerType: (implementationType: RegisteredInstanceType) => {
as: (instanceType: InstanceType<any>) => {
registerType: (implementationType: InstanceType<RegisteredType>) => {
as: (type: any) => {
with: (...injectionParams: any[]) => void;

@@ -11,6 +11,6 @@ };

registerInstance: (instance: any) => {
as: (instanceType: InstanceType<any>) => void;
as: (type: any) => void;
};
resolve: <TType extends Constructor & Partial<ConstructorParams> = any>(instanceType: TType, ...args: any[]) => InstanceType<TType>;
resolve: <TType extends Constructor & Partial<ConstructorParams> = any>(type: TType, ...args: any[]) => InstanceType<TType>;
};
export { container };

@@ -19,7 +19,7 @@ "use strict";

return {
as: (instanceType) => {
if (dependencies.has(instanceType)) {
throw new Error(`The instance type (${instanceType.name}) is already registered`);
as: (type) => {
if (dependencies.has(type)) {
throw new Error(`The instance type (${type.name}) is already registered`);
}
dependencies.set(instanceType, implementationType);
dependencies.set(type, implementationType);
return {

@@ -35,23 +35,23 @@ with: (...injectionParams) => {

return {
as: (instanceType) => {
if (dependencies.has(instanceType)) {
throw new Error(`The instance type (${instanceType.name}) is already registered`);
as: (type) => {
if (dependencies.has(type)) {
throw new Error(`The instance type (${type.name}) is already registered`);
}
dependencies.set(instanceType, instance);
dependencies.set(type, instance);
},
};
},
resolve: function (instanceType, ...args) {
if (dependencies.has(instanceType)) {
return makeInstance(instanceType, args);
resolve: function (type, ...args) {
if (dependencies.has(type)) {
return makeInstance(type, args);
}
if (!instanceType.__constructorParams || !Array.isArray(instanceType.__constructorParams)) {
throw new Error(`The ${instanceType.name} cannot be resolved by Dependency Injection`);
if (!type.__constructorParams || !Array.isArray(type.__constructorParams)) {
throw new Error(`The ${type.name} cannot be resolved by Dependency Injection`);
}
const dependencyArguments = [];
instanceType.__constructorParams.forEach((type) => {
type.__constructorParams.forEach((type) => {
const instance = container.resolve(type);
dependencyArguments.push(instance);
});
return new instanceType(...[
return new type(...[
...dependencyArguments,

@@ -58,0 +58,0 @@ ...args,

{
"name": "cheap-di",
"version": "0.1.3",
"version": "0.1.4",
"description": "JavaScript dependency injection like Autofac in .Net",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

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