0.0.6 • Published 8 years ago

radford v0.0.6

Weekly downloads
9
License
ISC
Repository
github
Last release
8 years ago

Radford: a service container and dependency injector for your application

Installation

npm install radford

Description

Radford is a lightweight service container for managing initialization and dependencies inside your app. Each service can request other services, and service can take optional arguments. This allows the components of your application to stay uncoupled from one another and Radford will build the service graph for you.

Usage

import Radford from "radford";
import { native: pgnative } from "pg";
import wrap from "pg.promised";

const cache = {};
const radford = new Radford({
    definitions: {
        db: {
            dependencies: [
                ["logger", {
                    name: "db",
                }],
            ],

            create: ({ logger }, {}) => {
                if (!cache.db) {
                    cache.db = wrap(pgnative);
                }

                return cache.db;
            },
        },

        logger: {
            create: ({}, { name }) {
                cache.logger = cache.logger || {};

                if (!cache.logger[name]) {
                    cache.logger[name] = function (...messages) {
                        console.log(`[${ name.toUpperCase() }]`, ...messages);
                    };
                }

                return cache.logger[name];
            },
        },
    },
});

const { db } = radford.invoke("db");

db.query() //...
0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

2.0.0

9 years ago

1.0.0

9 years ago