
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@travisk/practice-lib
Advanced tools
--- 
This is a minimal IoC / DI Container that supports injection of dependencies for TypeScript.
Feature Set:
Install the package via npm
npm install @travisk/practice-lib
Ensure you install reflect-metadata
as this library requires it
npm install reflect-metadata
Import reflect-metadata
when using the decorators such as @Service
import 'reflect-metadata';
Enable decorators and metadata within your tsconfig.json
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
Injecting constructor dependencies (Transient by default)
@Service
above the class declaration to allow constructor injectionimport 'reflect-metadata';
import { Service } from "./decorators";
import { Container } from './container';
class UserRepository {
getAllUserIds(): number[] {
return [1, 2];
}
}
@Service()
class UserService {
constructor(private userRepo: UserRepository) {}
getUserData = (): number[] => {
return this.userRepo.getAllUserIds();
}
}
const container = new Container();
const userService = container.get(UserService);
const userIds = userService.getUserData(); // returns [1, 2]
Injecting Singleton dependencies
import 'reflect-metadata';
import { Service } from "./decorators";
import { Container } from './container';
class UuidGenerator {
private uuid;
constructor(){
this.uuid = new randomUuid(); // generate uuid
}
getUuid(): string {
return this.uuid;
}
}
@Service('Singleton')
class TestClass {
constructor(private uuidGen: UuidGenerator) {}
getUserId = (): string => {
return this.uuidGen.getUuid();
}
}
const container = new Container();
const service1 = container.get(TestClass);
const service2 = container.get(TestClass);
service1.getUserId() === service2.getUserId(); // returns true
Injecting Objects
import 'reflect-metadata';
import { Container } from './container';
const container = new Container();
container.register('token', {hello: 'world'});
const obj = container.get('token'); // returns { hello: 'world' }
npm run lint
npx changeset
to initialise a version bump (patch, minor, major)FAQs
--- 
We found that @travisk/practice-lib 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.