Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
autoinject
Advanced tools
Readme
Auto dependency injector for typescript.
This is a proof of concept project, it may not be stable.
$ npm install autoinject
import {autoInject, dependencyInjection} from 'autoinject';
class User {
test = 'It works fine';
}
@autoInject
class Db {
user: User;
constructor(user: User) {
this.user = user;
}
}
@autoInject
class MyClass {
db: Db;
constructor(db: Db) {
this.db = db;
}
}
const myClass = dependencyInjection(MyClass);
console.log(myClass.db.user.test);
All dependencies are stored on a static prototype on the target object.
import {autoInject} from 'autoinject';
import {Db} from 'db';
@autoInject
class Controller {
constructor(db: Db) {}
}
console.log(Controller.inject); // [ Db ]
You can also auto instantiate a class
import {autoInject, autoInstantiate} from 'autoinject';
class User {
test = 'It works fine';
}
@autoInjecte
class Db {
constructor(public user: User) {}
}
@autoInstantiate
class MyClass {
constructor(public db?: Db) {}
}
var k = new MyClass();
console.log(k.db.user.test); // output: "It works fine"
You can always override the inject (for testing purpose)
// http.ts
class Http {
get(url: string) {
// some logic
}
}
export {Http};
// image-repository.ts
import {autoInject} from 'autoinject';
import {Http} from './http';
@autoInjecte
class ImageRepository {
http: Http;
constructor(http: Http) {
this.http = http;
}
getImage() {
return this.http.get('/image');
}
}
export {ImageRepository};
// test.ts
import {dependencyInjection} from 'autoinject';
import {ImageRepository} from './image-repository';
const httpMock = {
get() {
return 'Nice';
}
};
ImageRepository.inject = [httpMock];
const imageRepository = dependencyInjection(ImageRepository);
console.assert(imageRepository.getImage(), 'Nice');
Include the typing with:
"moduleResolution": "node"
in your tsconfig.json
FAQs
Autoinject classes
The npm package autoinject receives a total of 23 weekly downloads. As such, autoinject popularity was classified as not popular.
We found that autoinject 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.