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

micro-di

v1.1.16

Published

Config-based dependency injection container for node.js, inspired by Symfony2 (PHP) and Spring (Java)

Downloads

41

Readme

Micro DI

Config-based dependency injection container for node.js, inspired by Symfony2 (PHP) and Spring (Java).

Features

  • based on hyper-config: config wrapper with merging, references, string macros, tagging, etc.
  • supports annotation
  • injects to constructor as options object or arguments
  • can clone di container with new context (container per requests)

Config keywords

  • @class - reference to class, container creates new instance of prototype
  • @factory - reference to factory function, which returns initialized object, container invoke this function and cache result
  • ~path - reference, see hyper-config
  • @inject - constructor injection type: object, arguments, props
  • @tags - array of tags, see hyper-config

Usage

# ./config/ex2.all.yml
app:
    console-transport:
        @class: ~App.Transport.Console
        @tags: [req]
        prefix: console-prefix
    logger:
        @class: ~App.Logger
        @scope: req
        helper:
            @factory: ~App.Helper
            @inject: arguments
            text: helper text
            value: helper value
        transports:
            console: ~app.console-transport
        prefix: logger-prefix
var MicroDi = require('micro-di');
var ConfigLoader = require('node-config-loader');

function ConsoleTransport(options) {
    this._prefix = options.prefix;
    this._reqQuery = null;
}

ConsoleTransport.prototype.write = function (message) {
    console.log(this._prefix + ', ' + this._reqQuery + ': ' + message);
};

ConsoleTransport.prototype.setReq = function (req) {
    this._reqQuery = req.query;
};

function Logger(options) {
    this._helper = options.helper;
    this._transports = options.transports;
    this._prefix = options.prefix;
}

Logger.prototype.log = function (message) {
    this._transports.console.write(this._helper(this._prefix + ': ' + message));
};

function Helper(value, text) {
    return function (message) {
        return message + ', helper: ' + value + ', ' + text;
    };
}

var modules = {
    App: {
        Transport: {
            Console: ConsoleTransport
        },
        Logger: Logger,
        Helper: Helper
    }
};


var builder = MicroDi()
    .addConfig(modules);

ConfigLoader({env: 'dev'})
    .addConfigPath(__dirname + '/config')
    .load(function (config) {
        builder.addConfig(config);
    });

var container = builder.getContainer();

var req = {
    query: 'test query'
};
var newContainer = container.setContext('req', {
    req: req
});

var logger = newContainer.get('app.logger');
logger.log('message');
//console-prefix, test query: logger-prefix: message, helper: helper value, helper text