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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@b-mo/injector

v0.7.0

Published

dependency injector for bmo

Downloads

20

Readme

BMO Injector

The DI or dependency injection that BMO supplies is meant to be totally unobtrusive. Simply attach your constructor to the root dependencies export, and deconstruct your modules dependencies off of the manifest passed to each constructor.

Why dependency injection over import?

When you import a module, your are coupling your module directly to the imported module. References to dependencies are hard coded and strewn throughout the code base. If you need to change a dependency or module you have to update every reference to it and ensure that the interface was not broken. Using dependency injection allows you to wrap your external dependencies in modules that are then shared through the DI framework. Any changes or updates are isolated to the one module, and percolated from that single point.

Example Module

export default async ({ config, dependencies :{ connectionPool } }) => ({
    query:async (query) => {
      const connection = await connectionPool.getConnection();
      const result = await connection.execute(query)
      return result;
    }
  })

Using the dependency injector

import inject from '@b-mo/injector'

const dependencies = {
  //... a collection of your modules
}

const config = {
  //.... your configuration
}

// the manifest contains your created bundle
const manifest = await inject(config, dependencies)

//??
//profit

When the manifest is created the injector traverses your dependency tree injecting each modules dependencies eventually ending up with an object with all your build modules.

Package dependencies and built in modules:

The injector will detect and load nodejs builtin modules into your dependency context for you. To use packages defined in your package.json populate the 'pkg' key on your config with the package.json structure and the dependency injector will also automatically load any dependencies requested in modules. Some of the other tools will do this for you, but if you use this package directly you will need to load it yourself.

Sub Contexts

Sometimes it is useful to be able to create an isolated dependency context within your dependencies. The injector supplies a built in module to do this called context you can access it in any module being run through the dependency injector

export default ({
  config,
  dependencies:{
    baz,
    bmo: { di: { context } }
  }
}) => context()
      .config(config)// sets the config for the context
      .inherit({
        baz
      })
      .dependencies({ //sets the dependencies for the module
        foo,
        bar
        //... your submodule dependencies
      })
      .expose({
        foo:true,
      })
      .module()

Known Limitations

Any tools that modify the AST of your code may break dependency injection

Using transpilers, minifiers, or uglifiers that modify the AST may or may not work. (probably won't)