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

ioc-service-container

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ioc-service-container - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

3

dist/decorators.js

@@ -19,3 +19,4 @@ "use strict";

function get() {
return ServiceContainer_1.default.get((serviceId === null || serviceId === void 0 ? void 0 : serviceId.toLowerCase()) || propertyKey.toLowerCase());
var _a;
return ServiceContainer_1.default.get((_a = serviceId === null || serviceId === void 0 ? void 0 : serviceId.toLowerCase()) !== null && _a !== void 0 ? _a : propertyKey.toLowerCase());
}

@@ -22,0 +23,0 @@ function set() {

@@ -6,3 +6,3 @@ declare const _default: {

* @param factoryOrClassReference to create the instance of the service
* @param buildInstantly by default the service is only instantiated on demand, if required your are able to build the service directly
* @param buildInstantly by default the service is only instantiated on demand, if required you are able to build the service directly
*/

@@ -9,0 +9,0 @@ set(id: string, factoryOrClassReference: Factory | Function, buildInstantly?: boolean): void;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
let services = [];
let services = {};
exports.default = {

@@ -9,18 +9,14 @@ /**

* @param factoryOrClassReference to create the instance of the service
* @param buildInstantly by default the service is only instantiated on demand, if required your are able to build the service directly
* @param buildInstantly by default the service is only instantiated on demand, if required you are able to build the service directly
*/
set(id, factoryOrClassReference, buildInstantly = false) {
const lowerId = id.toLowerCase();
if (services.find(s => s.id === lowerId) !== undefined) {
if (this.isSet(lowerId)) {
throw new Error(`Service [${id}] is already registered`);
}
let factory = getFactory(factoryOrClassReference);
services.push({
id: lowerId,
factory,
instance: buildInstantly ? factory() : undefined,
});
this.override(lowerId, factoryOrClassReference, buildInstantly);
},
get(id) {
const service = services.find(s => s.id === id.toLowerCase());
var _a;
const service = services[id.toLowerCase()];
if (!service) {

@@ -30,3 +26,4 @@ throw new Error(`No service is registered for [${id}]`);

if (!service.instance) {
service.instance = service.factory();
service.instance = (_a = service.factory) === null || _a === void 0 ? void 0 : _a.call(service);
service.factory = undefined;
}

@@ -37,21 +34,13 @@ return service.instance;

const lowerId = id.toLowerCase();
const index = services.findIndex(s => s.id === lowerId);
let factory = getFactory(factoryOrClassReference);
const service = {
id: lowerId,
factory,
services[lowerId] = {
factory: buildInstantly ? undefined : factory,
instance: buildInstantly ? factory() : undefined,
};
if (index === -1) {
services.push(service);
}
else {
services[index] = service;
}
},
isSet(id) {
return services.some(s => s.id === id.toLowerCase());
return services[id.toLowerCase()] !== undefined;
},
reset() {
services = [];
services = {};
}

@@ -58,0 +47,0 @@ };

{
"name": "ioc-service-container",
"version": "1.6.0",
"version": "1.6.1",
"description": "Lightweight ioc service container",

@@ -16,8 +16,8 @@ "main": "dist/index.js",

"devDependencies": {
"@types/jest": "^29.2.4",
"jest": "^29.3.1",
"sonarqube-scanner": "^2.8.1",
"ts-jest": "^29.0.3",
"ts-node": "^10.4.0",
"typescript": "^4.9.3"
"@types/jest": "^29.5.3",
"jest": "^29.6.2",
"sonarqube-scanner": "^2.9.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
},

@@ -24,0 +24,0 @@ "files": [

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