Giter Club home page Giter Club logo

controlled's Introduction

Controlled

Build Status

Minimal toolkit to use Express with DI. Powered by Containor.

  • Use controllers in Express with ease.
  • Lazy instantiate controllers.
  • Inject services using DI.
  • Use middleware with DI.

Getting started

Setting up Controlled is very simple, we need to have Express and Containor (for our dependency injection) too and we are good to go!

Installation

Controlled (and Containor) can be installed by using any package manager using the npm repository.

npm install express containor controlled

With yarn:

yarn add express containor controlled

Controlled ships with Typescript types included, these do not have to be installed separately.

Basic usage

import express, { Request, Response } from "express";
import { createContainer, token } from "containor";
import { createControlled } from "controlled";

const app = express();
const container = createContainer();
const controlled = createControlled(container);

const tokens = {
  healthController: token<HealthController>("healthController"),
};

class HealthController {
  get(req: Request, res: Response): void {
    res.sendStatus(200);
  }
}

container.add(tokens.healthController, HealthController);

app.get("/health", controlled(tokens.healthController, "get"));

app.listen(8080);

As you can see, Controlled doesn't get in the way of your regular Express code, the only difference is the request handler is now created by Controlled!

controlled's People

Contributors

ngerritsen avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.