Skip to content
forked from ovesco/diosaur

A dependency injection library for Deno and Node

Notifications You must be signed in to change notification settings

SutroOrg/diosaur

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sutro Diosaur

A small dependency injection for Deno

Sutro Diosaur is a small dependency injection solution written in Typescript for Denowhich aims at making you write the minimum of code, avoiding obvious bindings and other repetitive stuff.

It's a fork of the excellent diosaur, but with the non-Deno stuff taken out. In particular, it removes the reliance on reflect-metadata since that isn't fully supported in Deno.

Example

import {
  Service,
  Parameter,
  Inject,
  setParameter,
  getContainer,
} from "diosaur";

@Service()
class Doggo {
  constructor(@Parameter("doggoName") private name: string) {}

  bark() {
    return this.name.toUpperCase();
  }
}

@Service()
class JonSnow {
  @Inject({ identifier: Doggo })
  private doggo: Doggo;

  yell() {
    return `I'm Jon with my doggo ${this.doggo.bark()} !`;
  }
}

setParameter("doggoName", "Ghost");

const container = await getContainer();
const jon = container.get(JonSnow);
console.log(jon.yell());

The key difference here is the need to provide explicit identifiers for @Inject

Documentation

About

A dependency injection library for Deno and Node

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%