Skip to content
Bunshi
GitHub

MoleculeInjector

MoleculeInjector: { createSubscription: ; get: ; use: ; useLazily: ; useScopes: ; } & Record< symbol, unknown >

Builds the graphs of molecules that make up your application.

The injector tracks the dependencies for each molecule and uses bindings to inject them.

This “behind-the-scenes” operation is what distinguishes dependency injection from its cousin, the service locator pattern.

From Dependency Injection: https://en.wikipedia.org/wiki/Dependency_injection

The injector, sometimes also called an assembler, container, provider or factory, introduces services to the client. The role of injectors is to construct and connect complex object graphs, where objects may be both clients and services. The injector itself may be many objects working together, but must not be the client, as this would create a circular dependency. Because dependency injection separates how objects are constructed from how they are used, it often diminishes the importance of the new keyword found in most object-oriented languages. Because the framework handles creating services, the programmer tends to only directly construct value objects which represents entities in the program’s domain (such as an Employee object in a business app or an Order object in a shopping app).

This is the core of bunshi, although you may rarely interact with it directly.

MoleculeInjector.createSubscription

createSubscription

MoleculeInjector.get

get

MoleculeInjector.use

use

MoleculeInjector.useLazily

useLazily

MoleculeInjector.useScopes

useScopes

Source

injector.ts:75