Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@wessberg/di
Advanced tools
A Dependency-Injection container that holds services and can produce instances of them as required. It mimics reflection by parsing the app at compile-time and supporting the generic-reflection syntax.
A Dependency-Injection container that holds services and can produce instances of them as required. It mimics reflection by parsing the app at compile-time and supporting the generic-reflection syntax.
Simply do: npm install @wessberg/di
.
DI
is truly a fresh take on dependency injection in a TypeScript/JavaScript environment:
registerSingleton<Interface, Implementation>()
. No need for anything else.import {DIContainer} from "@wessberg/di";
DIContainer.registerSingleton<IFoo, Foo>();
DIContainer.registerTransient<IBar, Bar>();
DIContainer.get<IBar>(); // Retrieves a concrete instance of the IBar service.
// And so on...
Sometimes, you may want to invoke the constructor of a service with custom arguments, rather than relying on every other non-initialized parameter of the service constructor to be dependency injected.
You can do that by passing a function that returns a new instance of the provided service as the first argument registerSingleton
or registerTransient
.
DIContainer.registerSingleton<IFoo, Foo>(() => new Foo("customArg", 123, "foo"));
To make the injections work - and to support the generic reflection notation - you need to compile the source code with the DI-Compiler.
If you are using Rollup, then use rollup-plugin-di to compile your code automatically as part of your bundle.
It uses CodeAnalyzer to check all of your code and all of its dependencies recursively to track classes and the constructor arguments they take (and their order). When a DIContainer
constructs a new instance of a service, it knows which concrete implementations match interfaces that exists in the signature of class constructors.
FAQs
A compile-time powered Dependency-Injection container for Typescript that holds services and can produce instances of them as required.
We found that @wessberg/di demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.