
Security News
Feross on the 10 Minutes or Less Podcast: Nobody Reads the Code
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.
@undermuz/inversify-generator
Advanced tools
A lightweight CLI tool that automatically sets up InversifyJS in any JS or Nx-based project
A lightweight CLI tool that automatically sets up InversifyJS in any Js or Nx-based project. It installs required dependencies, generates di structure, and configures a ready-to-use di setup.
👉 Learn more about the underlying DI framework at inversify.io.
package.json with required dependenciesRun the generator inside your project:
# Simple react project
npx @undermuz/inversify-generator@latest init
# NX-like project
npx @undermuz/inversify-generator@latest init --project=./apps/web-app/src
By default, it installs di files into:
<cwd>/src
<cwd>/package.json
To specify a custom path:
npx @undermuz/inversify-generator init --project=apps/web-app/src
<cwd>/apps/web-app/src
<cwd>/package.json
After initialization, you can add new modules using:
npx @undermuz/inversify-generator add-module <name>
<cwd>/src/di/<name>
Examples:
# Add a "settings" module (uses default src)
npx @undermuz/inversify-generator add-module settings
# Add a "session" module
npx @undermuz/inversify-generator add-module session
# Specify custom app path (module directory will be created inside apps/web-app/src/di)
npx @undermuz/inversify-generator add-module dashboard --project=apps/web-app/src
The command will:
di/ directorytypes.tsprovider.ts with providermodule.ts with container modulecontainer.ts to include the new moduleAfter initialization, you can add predefined preset modules using:
npx @undermuz/inversify-generator add-preset-module <selector>
<cwd>/src/di/<selector>
<selector> supports nested preset paths (for example utils/cache, logger/logtape).
Selectors that do not have their own preset.json are treated as preset groups and cannot be added directly.
Examples:
# Add the "env" preset module
npx @undermuz/inversify-generator add-preset-module env
# Add the "react" preset module
npx @undermuz/inversify-generator add-preset-module react
# Add nested utility preset
npx @undermuz/inversify-generator add-preset-module utils/cache
# Choose concrete logger implementation
npx @undermuz/inversify-generator add-preset-module logger/logtape
# Specify custom app path
npx @undermuz/inversify-generator add-preset-module env --project=apps/web-app/src
The command will:
presets/<name> to the app's di/ directorymodule.ts, automatically update the main container.ts to include the new moduledi/
container.ts
my-provider/
types.ts
module.ts
provider.ts
When you add a new module using add-module, the following files are created:
di/
my-new-module/
types.ts
module.ts
provider.ts
container.tsx # (automatically updated)
When you add a preset module using add-preset-module, files are copied according to preset manifests:
di/
<PRESET_SELECTOR>/ # copied from presets/<PRESET_SELECTOR>
<FILES_FROM_MANIFEST>
<DEPENDENCY_SELECTOR>/
<DEPENDENCY_FILES_FROM_MANIFEST>
container.ts # updated for presets with a declared module
Each standalone preset has preset.json with:
files: what to copymodule (optional): what to import/load into container.tsdependencies (optional): dependent preset selectors and optional file subsetsTo auto-suggest dependencies from relative imports:
# preview dependencies
npm run preset:deps -- utils/cache
# write dependencies to presets/<selector>/preset.json
npm run preset:deps -- utils/cache --write
After running the generator and adding modules, you can use the container in your application code. Typical workflow:
// src/di/container.ts (generated)
import { Container } from "inversify";
import { someModule } from "./some-module/module";
export const container = new Container();
container.load(someModule);
// src/di/some-module/types.ts
export const TYPES = {
SomeService: Symbol.for("SomeService"),
};
// src/di/some-module/provider.ts
import { injectable } from "inversify";
import { createSomeService } from "./service";
@injectable()
export class SomeService {
constructor() {}
sayHi() { console.log("hello from injected service"); }
}
// src/index.ts
import "reflect-metadata"; // required by inversify
import { container } from "./di/container";
import { TYPES } from "./di/some-module/types";
import { SomeService } from "./di/some-module/provider";
const service = container.get<SomeService>(TYPES.SomeService);
service.sayHi();
If you generated the react preset (or manually set up the bindings), you can expose the container via a provider and consume it in components:
// src/App.tsx
import React from "react";
import { useDi } from "./di/ReactProvider";
import { TYPES } from "./di/some-module/types";
import { SomeService } from "./di/some-module/provider";
import { DiProvider } from "./di/ReactProvider";
function Page() {
const container = useDi();
const service = container.get<SomeService>(TYPES.SomeService);
React.useEffect(() => {
service.sayHi();
}, [service]);
return <div>Check the console for a greeting</div>;
}
function App() {
return (
<DiProvider>
<Page />
</DiProvider>
);
}
export default App;
The examples above show basic binding and retrieval; for more advanced patterns check the Inversify docs.
Run the test suite:
npm test
Tests cover the core actions: copying files, updating package.json, generating modules, and configuring TypeScript. Uses Vitest for fast, ESM-compatible testing.
Clone the repository and link it globally:
npm install
npm link
Now the CLI is available system-wide:
inversify-generator
MIT
FAQs
A lightweight CLI tool that automatically sets up InversifyJS in any JS or Nx-based project
We found that @undermuz/inversify-generator demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.