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

dm

v0.5.0

Published

Dependency Injection Manager

Downloads

408

Readme

dm.js

NPM version Build Status Coverage Status

Dependency Injection Manager for javascript.

Introduction

dm.js is a javascript library that implements dependency injection pattern. It could work both in node or browser.

It takes care of asynchronous creating, configuring and injecting objects aka services inside of your code.

There is a good chance to keep your application design loose coupled, well structured and flexible with dependency injection pattern.

If you are not familiar with dependency injection pattern, use wiki to get more theory info.

Usage


var DM     = require("dm"),
    Async  = require("dm/lib/async/q"),
    Loader = require("dm/lib/loader/cjs"),
    dm;

dm = new DM(new Async(Q), new Loader(require), {
    parameters: {
        "logs": "/var/log/app/"
    },

    services: {
        "logger": {
            // this is where the loader must get a constructor for this service
            "path": "./src/log/logger/polylogue.js",
            
            // this is what calls dm must do on just created service
            "calls": [
            
                // '@' symbol is the link to another service from config
                [ "addHandler", ["@handler"] ]
                
            ]
        },

        "handler": {
            "path": "./src/log/handler/file.js",
            
            // this is what arguments pass to the constructor
            "arguments": [
                {
                    // '%' symbol is the getter of parameter from config (defined above)
                    // curly braces is a kinda simple templating feature (works with '@', '#' and '%')
                    "path": "%{logs}/log.txt"
                }
            ]
        }
    }
});


dm
    .get("logger")
    .then(function(logger) {
        // now we got instantiated and configured logger
        logger.info("Hello! It works!");
    });

Quick overview

DM can:

  • call constructor of your object with needed arguments;
  • make any calls on created object with any arguments;
  • directly set some properties;
  • pass as dependency another service from configuration, or its property, or its method, or its method call result;
  • pass as dependency some file content (with fs.readFile in cjs, and require(text!) in amd);
  • pass as dependency value of parameters, defined in configuration object;
  • pass as dependency some static string with wildcards, that could be any kind of dependencies above;
  • cache or always create new object;
  • retrieve already created objects and work with them as cached services;
  • be configured on the fly with new definitions of services;
  • use custom factory for the service, to make more complex things;

Full syntax definition you can find in the wiki.

Documentation

There is a wiki for dive deep with dm usage, syntax and ideology. Also, you can check the API docs.

Contributing

All developing version are available to install from npm as [email protected]. To publish new release candidate (rc abbr) just do npm publish --tag x.y.z-rc and bump version in package.json x.y.z-rc0.

License

MIT