Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@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.
The npm package @wessberg/di receives a total of 527 weekly downloads. As such, @wessberg/di popularity was classified as not popular.
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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.