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 🙏

© 2024 – Pkg Stats / Ryan Hefner

dependency-injection-promise

v0.1.1

Published

Here you don't bind to interfaces, but to typed properties in a config JSON-as-js. It's a way to modularize a service with asynchronously configured components. The primary motivation is testability. You inject dependencies by passing the config objects.

Downloads

7

Readme

Here you don't bind to interfaces, but to typed properties in a config JSON-as-js. It's a way to modularize a service with asynchronously configured components. The primary motivation is testability. You inject dependencies by passing the config objects. It's very close to what you end up doing anyway, because you tend to need promises to initialize components.

Modularization (like Guice's Modules) can be achived by nesting levels in config. Can be an afterthought by introducing thew config source files that wrap the original config, without renaming and .

Note that this is Inversion of Control: for DependencyLazy nothing will import the actual provider unless you do so.

Say what?

This is some kind of inversion of Inversion of Control :) and it's based on how we've productively developed small services:

  • There's a main, like src/index.js (package.json says so)
  • There's a config.js (not JSON because it has no comment syntax and can't read process.env)
  • Config declares constant, synchronous, parameters like connection strings.

Now we attempt to add:

  • In addition to constants, config declares modules, for example:
    • An established connection to a backend
    • A feature that exposes an API
  • Main does imports (or requires) to select implementations.
  • Modules that depend on other modules don't import, they read from config.
    • And while they too import config at the top, they can at the same time provide impls for such modules.
  • The framework essentially defers the resolution (or "providers") of these modules until needed.
    • And guards agains multiple implementations of the same module.

This means that there's one main for production, one main for integration tests, no main for unit tests :), separate mains elswhere if the package is used as npm dependency.

The global require of config is the weak part here, in particular if used as lib, but it has worked very well for simple services and we're not only aiming a little bit higher now.

The desired outcome is to avoid hierarchies of modues initializing each other, i.e. to simplify and clarify a production setup. As with regular dependency injection this should also make TDD more practical.