npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@openshift-migration-advisor/ioc

v0.22.0

Published

A basic IoC solution for React apps (inspired by InversifyJs)

Readme

@openshift-migration-advisor/ioc

A lightweight Inversion of Control (IoC) container solution for React applications, inspired by InversifyJS.

Installation

npm install @openshift-migration-advisor/ioc --save

or

yarn add @openshift-migration-advisor/ioc

Usage

1. Define Symbols for Your Dependencies

Create a symbols file to define unique identifiers for your dependencies:

// Symbols.ts
export const Symbols = Object.freeze({
  MyService: Symbol.for("MyService"),
  ApiClient: Symbol.for("ApiClient"),
});

2. Create and Configure the Container

Create a container instance and register your dependencies:

import { Container } from "@openshift-migration-advisor/ioc";
import { Symbols } from "./Symbols";
import { MyService } from "./services/MyService";
import { ApiClient } from "./clients/ApiClient";

function getConfiguredContainer(): Container {
  const container = new Container();

  // Register dependencies
  container
    .register(Symbols.MyService, new MyService())
    .register(Symbols.ApiClient, new ApiClient());

  return container;
}

3. Provide the Container to Your App

Wrap your application with the Provider component:

import { Provider } from "@openshift-migration-advisor/ioc";
import React from "react";
import ReactDOM from "react-dom/client";

const container = getConfiguredContainer();

ReactDOM.createRoot(document.getElementById("root")!).render(
  <React.StrictMode>
    <Provider container={container}>
      <App />
    </Provider>
  </React.StrictMode>
);

4. Use Dependencies in Components

Use the useInjection hook to retrieve dependencies in your React components:

import { useInjection } from "@openshift-migration-advisor/ioc";
import { Symbols } from "./Symbols";
import type { MyServiceInterface } from "./services/MyService";

export const MyComponent: React.FC = () => {
  const myService = useInjection<MyServiceInterface>(Symbols.MyService);

  // Use the injected service
  const handleClick = () => {
    myService.doSomething();
  };

  return <button onClick={handleClick}>Click me</button>;
};

API Reference

Container

A singleton-scoped dependency injection container.

Methods

register<T>(symbol: symbol, value: T): Container

Registers a dependency with the container.

  • Parameters:
    • symbol: A unique symbol identifier for the dependency
    • value: The value to register
  • Returns: The container instance (for method chaining)
get<T>(symbol: symbol): T | undefined

Retrieves a registered dependency from the container.

  • Parameters:
    • symbol: The symbol identifier of the dependency to retrieve
  • Returns: The registered dependency value, or undefined if not registered.

Provider

A React context provider component that makes the container available to child components.

Props

  • container: Container - The container instance to provide
  • children: React.ReactNode - Child components

useInjection<T>(symbol: symbol): T

A React hook that retrieves a dependency from the container.

  • Parameters:
    • symbol: The symbol identifier of the dependency to retrieve
  • Returns: The registered dependency value
  • Throws: ReferenceError if used outside a Provider

Example

Here's a complete example demonstrating the full usage:

// 1. Define symbols
export const Symbols = Object.freeze({
  UserApi: Symbol.for("UserApi"),
});

// 2. Create and configure container
import { Container, Provider } from "@openshift-migration-advisor/ioc";
import { UserApi } from "./api/UserApi";

const container = new Container();
container.register(Symbols.UserApi, new UserApi());

// 3. Provide container to app
function App() {
  return (
    <Provider container={container}>
      <UserProfile />
    </Provider>
  );
}

// 4. Use dependency in component
import { useInjection } from "@openshift-migration-advisor/ioc";

function UserProfile() {
  const userApi = useInjection(Symbols.UserApi);
  const [user, setUser] = useState(null);

  useEffect(() => {
    userApi.getUser().then(setUser);
  }, [userApi]);

  return <div>{user?.name}</div>;
}

Features

  • Simple API: Minimal surface area with just a few core concepts
  • Type-safe: Full TypeScript support with generics
  • React-friendly: Designed specifically for React applications
  • Lightweight: No external dependencies beyond React
  • Singleton scope: All dependencies are singleton-scoped

Development

Building

yarn build

Code Quality

# Check code
yarn check

# Fix code issues
yarn check:fix

# Format code
yarn format

Cleaning

yarn clean

License

Apache 2.0