Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colony-framework

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colony-framework

A dependency injection server framework for TypeScript

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Colony Framework

This is a tool for dependency injection, using typescript in node.

Installation

npm install typescript --save-dev and then npm install colony-framework --save.

Usage

import { Injectable } from "colony-framework";

@Injectable
class MessageCreator {
  GetMessage() {
    return "Hello world";
  }
}

And then for the subject.

import { Injectable } from "colony-framework";

@Injectable
export class TestController {
  constructor(private readonly message_creator: MessageCreator) {
    super();
  }

  async GET(query: unknown) {
    return {
      status: 200,
      body: this.message_creator.GetMessage(),
    };
  }
}

Finaly build the tree.

import { TestController } "./test-controller";
import { Build } from "colony-framework";

const controller = Build(TestController);

Advanced usage

We can also use abstract base classes in the place of interfaces. This library uses reflect-metadata under the hood so interfaces are not currently available.

export default abstract class IMessageCreator {
  abstract GetMessage(): string;
}

Can be used as

import { InjectableAs } from "colony-framework";
import IMessageCreator from "./i-message-creator";

@InjectableAs(IMessageCreator)
class MessageCreator extends IMessageCreator {
  GetMessage() {
    return "Hello world";
  }
}

This can then be imported as IMessageCreator into other injectable classes.

We can also use custom initialisers on classes. These initialisers can be asynchronous.

import { InjectableWith } from "colony-framework";

@InjectableWith(() => new MessageCreator("Hello world"))
class MessageCreator {
  constructor(private readonly message: string) {
    super();
  }

  GetMessage() {
    return this.message;
  }
}

This can also take a second argument for as so as to use abstract base classes.

FAQs

Package last updated on 08 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc