Skip to content

distributed-ledger-technology/injector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dependency Injection

This module can be used to prepare for dynamic dependency injection - e.g. via constructor injection.

Usage Example

import { Animal } from "https://deno.land/x/[email protected]/src/demo/animal.ts" // for demo
import { Dog } from "https://deno.land/x/[email protected]/src/demo/dog.ts" // for demo
import { Horse } from "https://deno.land/x/[email protected]/src/demo/horse.ts" // for demo

import { Registry } from "https://deno.land/x/[email protected]/mod.ts"

const registry = new Registry()

registry.register(Dog)
registry.register(Horse)

const myDog: Animal = new (registry.get('Dog'))(3)
myDog.tellMeHowManyGoodiesDoYouLike()

const myHorse: Animal = new (registry.get('Horse'))(2)
myHorse.tellMeHowManyGoodiesDoYouLike()

Test it via your Console

deno run https://deno.land/x/injector/src/demo/start-demo.ts

Trigger Unit Tests via your Console

deno test https://deno.land/x/injector/src/registry.spec.ts

Donations

Thanks to Freedom Cash, we are already free.
If you want to donate, you might consider donating to the otherparty.co.uk to ensure people do not need to donate to victims but rather donate successfully to problem solvers.

direct-democracy