;const di = ;di;di;di;/* fast forward to... */const foo = di ? di : "Nope";
Putting things in the container
The API is designed to be as simple as possible, but no more so. The
singleton method in place of
register. This will guarantee the provided callback is called at most once (you can use the
singleton method with non-callback values too, but then it's functionally identical to
const foo = a b c;/* simple value store with arbitrary keys */di;/* lazy loading */di;/* singleton with dependencies */di;/* pointless, just use register for values */di;
Getting things out
You can use the
has method to see if a key is registered in the container. Using
has won't invoke any callbacks. Use
get to access the value of that key.
di;di; // truedi; // falsedi; // "bar"
npm install dosage# optionally run tests (you'll need tap installed)npm test