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

rsdi

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rsdi

dependency injection container

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
173
decreased by-77.91%
Maintainers
1
Weekly downloads
 
Created
Source

RSDI - Dependency Injection Container

Getting Started


import DIContainer, { object, get, value, factory, IDIContainer } from "rsdi";

const config = {
    "ENV": value("PRODUCTION"),             // define raw value
    "Storage": object(CookieStorage),       // constructor without arguments    
    "AuthStorage": object(AuthStorage).construct(
       get("Storage")                       // refer to dependency described above       
    ),
    "BrowserHistory": factory(configureHistory),   
};
const container = new DIContainer();
container.addDefinitions(config);

const env = container.get<string>("ENV"); // PRODUCTION
const authStorage = container.get<AuthStorage>("AuthStorage");  // object of AuthStorage
const history = container.get<History>("BrowserHistory");  // object of History


function configureHistory(container: IDIContainer): History {     
    const history = createBrowserHistory();
    const env = container.get("ENV");
    if (env === "production") {
        // do what you need
    }
    return history;
}

Motivation

Popular solution like inversify or tsyringe use reflect-metadata that allows to fetch argument types and based on that types and do autowiring. I like autowiring but the I don't like the means by which we achieve it. I don't like

  1. Those solutions in fact can deal only with typescript only. Since they rely on argument types that we don't have in JS.
  2. I have to update my tsconfig because of one package.
  3. Let my components know about injections
@injectable()
class Foo {  
}

Why component Foo should know that it's injectable?

Keywords

FAQs

Package last updated on 10 Jul 2019

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