
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ts-instance-manager
Advanced tools
An instance of the InstanceManager is exported as InstanceManager and the class as InstanceManagerClass
.isManaged(identifier: string): boolReturns if a Singleton or Managed Class with the provided identifier is managed.
instance(identifierOrObjectOrClass: any): ObjectIf an Singleton Instance for the provided identifier, instance or class is found it gets returned. Otherwise undefined is returned.
@Singleton(entryIdentifier?: string, attachInstaceMethod = false)
The entryIdentifier is used to reference the class in all other InstanceManager methods. If no entryIdentifier is provided the class name is used.
If attachInstaceMethod is true then the class gets a static Instance method attached to.
Every Singleton has to be instantiated once before it can be used in an injected property
To get an Instance of the Singleton use InstanceManager.instance(identifierOrObjectOrClass) method or the attached .Instance() method.
@Managed(entryIdentifier?: string)
@Inject(identifierOrObjectOrClass)
identifierOrObjectOrClass can be either an entryIdentifier , a class instance or the class itself.
class ExampleClass {
// you can also use: @Inject('OneTest')
// or: @Inject(OneTest)
@Inject(one)
protected oneTest = <OneTest><any>undefined
getTest() {
return this.oneTest.getTest()
}
}
The resetInstanceManagerInstanceTo function the current Instance Manager instance can be replaced. This is needed if an extended class of the InstanceManager should be used.
import { InstanceManagerClass, resetInstanceManagerInstanceTo } from 'ts-instance-manager'
class InstanceManager extends InstanceManagerClass {
doSomeThing() {
return 'something'
}
}
const InstanceManagerInstance = new InstanceManager()
resetInstanceManagerInstanceTo(InstanceManagerInstance)
export { InstanceManagerInstance as InstanceManager, InstanceManager as InstanceManagerClass }
import { InstanceManager, Managed, Singleton, Inject } from "./InstanceManager";
@Singleton('TestOne')
class OneTest {
test: string
constructor(test: string) {
this.test = test
}
getTest() {
return this.test
}
}
const one = new OneTest('one')
const two = new OneTest('two')
class ExampleClass {
// you can also use: @Inject('TestOne')
// or: @Inject(OneTest)
// or: @Inject(two)
@Inject(one)
protected oneTest = <OneTest><any>undefined
getTest() {
return this.oneTest.getTest()
}
}
// returns true
console.log(one === two)
// returns true
console.log(two === InstanceManager.instance(OneTest))
// returns true
console.log(InstanceManager.isManaged('TestOne'))
const inejctExample = new ExampleClass()
// returns 'one'
console.log(managedTest.getTest())
FAQs
An Instance Manager for Typescript
We found that ts-instance-manager demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.